Skip to content

Commit f959c12

Browse files
committed
Make completion based on imports configurable
1 parent 8b7b0c5 commit f959c12

File tree

7 files changed

+415
-23
lines changed

7 files changed

+415
-23
lines changed

server/src/__tests__/analyzer.test.ts

Lines changed: 137 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,59 @@ describe('commandNameAtPoint', () => {
222222
})
223223

224224
describe('findSymbolsMatchingWord', () => {
225-
it('return a list of symbols across the workspace', () => {
226-
analyzer.analyze('install.sh', FIXTURES.INSTALL)
227-
analyzer.analyze('sourcing-sh', FIXTURES.SOURCING)
225+
it('return a list of symbols across the workspace (with default config)', async () => {
226+
const parser = await initializeParser()
227+
const connection = getMockConnection()
228+
229+
const analyzer = new Analyzer({ console: connection.console, parser })
230+
await analyzer.initiateBackgroundAnalysis({
231+
rootPath: FIXTURE_FOLDER,
232+
})
228233

229234
expect(
230235
analyzer.findSymbolsMatchingWord({
231236
word: 'npm_config_logl',
232237
uri: FIXTURE_URI.INSTALL,
233238
exactMatch: false,
234239
}),
235-
).toMatchInlineSnapshot(`Array []`)
240+
).toMatchInlineSnapshot(`
241+
Array [
242+
Object {
243+
"kind": 13,
244+
"location": Object {
245+
"range": Object {
246+
"end": Object {
247+
"character": 27,
248+
"line": 40,
249+
},
250+
"start": Object {
251+
"character": 0,
252+
"line": 40,
253+
},
254+
},
255+
"uri": "file://${FIXTURE_FOLDER}install.sh",
256+
},
257+
"name": "npm_config_loglevel",
258+
},
259+
Object {
260+
"kind": 13,
261+
"location": Object {
262+
"range": Object {
263+
"end": Object {
264+
"character": 31,
265+
"line": 48,
266+
},
267+
"start": Object {
268+
"character": 2,
269+
"line": 48,
270+
},
271+
},
272+
"uri": "file://${FIXTURE_FOLDER}install.sh",
273+
},
274+
"name": "npm_config_loglevel",
275+
},
276+
]
277+
`)
236278

237279
expect(
238280
analyzer.findSymbolsMatchingWord({
@@ -248,15 +290,105 @@ describe('findSymbolsMatchingWord', () => {
248290
uri: FIXTURE_URI.INSTALL,
249291
exactMatch: false,
250292
}),
251-
).toMatchInlineSnapshot(`Array []`)
293+
).toMatchInlineSnapshot(`
294+
Array [
295+
Object {
296+
"kind": 13,
297+
"location": Object {
298+
"range": Object {
299+
"end": Object {
300+
"character": 19,
301+
"line": 6,
302+
},
303+
"start": Object {
304+
"character": 0,
305+
"line": 6,
306+
},
307+
},
308+
"uri": "file://${FIXTURE_FOLDER}extension.inc",
309+
},
310+
"name": "BLUE",
311+
},
312+
]
313+
`)
252314

253315
expect(
254316
analyzer.findSymbolsMatchingWord({
255317
word: 'BLU',
256318
uri: FIXTURE_URI.SOURCING,
257319
exactMatch: false,
258320
}),
321+
).toMatchInlineSnapshot(`
322+
Array [
323+
Object {
324+
"kind": 13,
325+
"location": Object {
326+
"range": Object {
327+
"end": Object {
328+
"character": 19,
329+
"line": 6,
330+
},
331+
"start": Object {
332+
"character": 0,
333+
"line": 6,
334+
},
335+
},
336+
"uri": "file://${FIXTURE_FOLDER}extension.inc",
337+
},
338+
"name": "BLUE",
339+
},
340+
]
341+
`)
342+
})
343+
344+
it('return a list of symbols accessible to the uri (when config.COMPLETION_BASED_ON_IMPORTS is true)', async () => {
345+
process.env = {
346+
COMPLETION_BASED_ON_IMPORTS: '1',
347+
}
348+
349+
const parser = await initializeParser()
350+
const connection = getMockConnection()
351+
352+
const analyzer = new Analyzer({ console: connection.console, parser })
353+
await analyzer.initiateBackgroundAnalysis({
354+
rootPath: FIXTURE_FOLDER,
355+
})
356+
357+
expect(
358+
analyzer.findSymbolsMatchingWord({
359+
word: 'BLU',
360+
uri: FIXTURE_URI.INSTALL,
361+
exactMatch: false,
362+
}),
259363
).toMatchInlineSnapshot(`Array []`)
364+
365+
expect(
366+
analyzer.findSymbolsMatchingWord({
367+
word: 'BLU',
368+
uri: FIXTURE_URI.SOURCING,
369+
exactMatch: false,
370+
}),
371+
).toMatchInlineSnapshot(`
372+
Array [
373+
Object {
374+
"kind": 13,
375+
"location": Object {
376+
"range": Object {
377+
"end": Object {
378+
"character": 19,
379+
"line": 6,
380+
},
381+
"start": Object {
382+
"character": 0,
383+
"line": 6,
384+
},
385+
},
386+
"uri": "file://${FIXTURE_FOLDER}extension.inc",
387+
},
388+
"name": "BLUE",
389+
},
390+
]
391+
`)
260392
})
261393
})
262394

server/src/__tests__/config.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,19 @@ describe('highlightParsingError', () => {
105105
expect(result).toEqual(false)
106106
})
107107
})
108+
109+
describe('getCompletionBasedOnImports', () => {
110+
it('default to false', () => {
111+
process.env = {}
112+
const result = config.getCompletionBasedOnImports()
113+
expect(result).toEqual(false)
114+
})
115+
116+
it('parses environment variable', () => {
117+
process.env = {
118+
COMPLETION_BASED_ON_IMPORTS: '1',
119+
}
120+
const result = config.getCompletionBasedOnImports()
121+
expect(result).toEqual(true)
122+
})
123+
})

0 commit comments

Comments
 (0)