Skip to content

Commit e447dd2

Browse files
committed
Make completion based on imports configurable
1 parent e39d485 commit e447dd2

File tree

7 files changed

+395
-23
lines changed

7 files changed

+395
-23
lines changed

server/src/__tests__/analyzer.test.ts

Lines changed: 139 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,60 @@ describe('wordAtPoint', () => {
205205
})
206206

207207
describe('findSymbolsMatchingWord', () => {
208-
it('return a list of symbols across the workspace', () => {
209-
analyzer.analyze('install.sh', FIXTURES.INSTALL)
210-
analyzer.analyze('sourcing-sh', FIXTURES.SOURCING)
208+
it('return a list of symbols across the workspace (with default config)', async () => {
209+
const parser = await initializeParser()
210+
const connection = getMockConnection()
211+
212+
const analyzer = await Analyzer.fromRoot({
213+
connection,
214+
rootPath: FIXTURE_FOLDER,
215+
parser,
216+
})
211217

212218
expect(
213219
analyzer.findSymbolsMatchingWord({
214220
word: 'npm_config_logl',
215221
uri: FIXTURE_URI.INSTALL,
216222
exactMatch: false,
217223
}),
218-
).toMatchInlineSnapshot(`Array []`)
224+
).toMatchInlineSnapshot(`
225+
Array [
226+
Object {
227+
"kind": 13,
228+
"location": Object {
229+
"range": Object {
230+
"end": Object {
231+
"character": 27,
232+
"line": 40,
233+
},
234+
"start": Object {
235+
"character": 0,
236+
"line": 40,
237+
},
238+
},
239+
"uri": "file://${FIXTURE_FOLDER}install.sh",
240+
},
241+
"name": "npm_config_loglevel",
242+
},
243+
Object {
244+
"kind": 13,
245+
"location": Object {
246+
"range": Object {
247+
"end": Object {
248+
"character": 31,
249+
"line": 48,
250+
},
251+
"start": Object {
252+
"character": 2,
253+
"line": 48,
254+
},
255+
},
256+
"uri": "file://${FIXTURE_FOLDER}install.sh",
257+
},
258+
"name": "npm_config_loglevel",
259+
},
260+
]
261+
`)
219262

220263
expect(
221264
analyzer.findSymbolsMatchingWord({
@@ -231,15 +274,106 @@ describe('findSymbolsMatchingWord', () => {
231274
uri: FIXTURE_URI.INSTALL,
232275
exactMatch: false,
233276
}),
234-
).toMatchInlineSnapshot(`Array []`)
277+
).toMatchInlineSnapshot(`
278+
Array [
279+
Object {
280+
"kind": 13,
281+
"location": Object {
282+
"range": Object {
283+
"end": Object {
284+
"character": 19,
285+
"line": 6,
286+
},
287+
"start": Object {
288+
"character": 0,
289+
"line": 6,
290+
},
291+
},
292+
"uri": "file://${FIXTURE_FOLDER}extension.inc",
293+
},
294+
"name": "BLUE",
295+
},
296+
]
297+
`)
235298

236299
expect(
237300
analyzer.findSymbolsMatchingWord({
238301
word: 'BLU',
239302
uri: FIXTURE_URI.SOURCING,
240303
exactMatch: false,
241304
}),
305+
).toMatchInlineSnapshot(`
306+
Array [
307+
Object {
308+
"kind": 13,
309+
"location": Object {
310+
"range": Object {
311+
"end": Object {
312+
"character": 19,
313+
"line": 6,
314+
},
315+
"start": Object {
316+
"character": 0,
317+
"line": 6,
318+
},
319+
},
320+
"uri": "file://${FIXTURE_FOLDER}extension.inc",
321+
},
322+
"name": "BLUE",
323+
},
324+
]
325+
`)
326+
})
327+
328+
it('return a list of symbols accessible to the uri (when config.COMPLETION_BASED_ON_IMPORTS is true)', async () => {
329+
process.env = {
330+
COMPLETION_BASED_ON_IMPORTS: '1',
331+
}
332+
333+
const parser = await initializeParser()
334+
const connection = getMockConnection()
335+
336+
const analyzer = await Analyzer.fromRoot({
337+
connection,
338+
rootPath: FIXTURE_FOLDER,
339+
parser,
340+
})
341+
342+
expect(
343+
analyzer.findSymbolsMatchingWord({
344+
word: 'BLU',
345+
uri: FIXTURE_URI.INSTALL,
346+
exactMatch: false,
347+
}),
242348
).toMatchInlineSnapshot(`Array []`)
349+
350+
expect(
351+
analyzer.findSymbolsMatchingWord({
352+
word: 'BLU',
353+
uri: FIXTURE_URI.SOURCING,
354+
exactMatch: false,
355+
}),
356+
).toMatchInlineSnapshot(`
357+
Array [
358+
Object {
359+
"kind": 13,
360+
"location": Object {
361+
"range": Object {
362+
"end": Object {
363+
"character": 19,
364+
"line": 6,
365+
},
366+
"start": Object {
367+
"character": 0,
368+
"line": 6,
369+
},
370+
},
371+
"uri": "file://${FIXTURE_FOLDER}extension.inc",
372+
},
373+
"name": "BLUE",
374+
},
375+
]
376+
`)
243377
})
244378
})
245379

server/src/__tests__/config.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,19 @@ describe('highlightParsingError', () => {
8181
expect(result).toEqual(false)
8282
})
8383
})
84+
85+
describe('getCompletionBasedOnImports', () => {
86+
it('default to false', () => {
87+
process.env = {}
88+
const result = config.getCompletionBasedOnImports()
89+
expect(result).toEqual(false)
90+
})
91+
92+
it('parses environment variable', () => {
93+
process.env = {
94+
COMPLETION_BASED_ON_IMPORTS: '1',
95+
}
96+
const result = config.getCompletionBasedOnImports()
97+
expect(result).toEqual(true)
98+
})
99+
})

0 commit comments

Comments
 (0)