Skip to content

Commit f195be5

Browse files
committed
Use entire workspace for completion symbols
1 parent 4cef262 commit f195be5

File tree

6 files changed

+318
-215
lines changed

6 files changed

+318
-215
lines changed

server/src/__tests__/__snapshots__/analyzer.test.ts.snap

Lines changed: 2 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -126,140 +126,7 @@ Array [
126126
]
127127
`;
128128

129-
exports[`findSymbolCompletions return a list of symbols 1`] = `
130-
Array [
131-
Object {
132-
"data": Object {
133-
"name": "ret",
134-
"type": 3,
135-
},
136-
"kind": 6,
137-
"label": "ret",
138-
},
139-
Object {
140-
"data": Object {
141-
"name": "configures",
142-
"type": 3,
143-
},
144-
"kind": 6,
145-
"label": "configures",
146-
},
147-
Object {
148-
"data": Object {
149-
"name": "npm_config_loglevel",
150-
"type": 3,
151-
},
152-
"kind": 6,
153-
"label": "npm_config_loglevel",
154-
},
155-
Object {
156-
"data": Object {
157-
"name": "node",
158-
"type": 3,
159-
},
160-
"kind": 6,
161-
"label": "node",
162-
},
163-
Object {
164-
"data": Object {
165-
"name": "TMP",
166-
"type": 3,
167-
},
168-
"kind": 6,
169-
"label": "TMP",
170-
},
171-
Object {
172-
"data": Object {
173-
"name": "BACK",
174-
"type": 3,
175-
},
176-
"kind": 6,
177-
"label": "BACK",
178-
},
179-
Object {
180-
"data": Object {
181-
"name": "tar",
182-
"type": 3,
183-
},
184-
"kind": 6,
185-
"label": "tar",
186-
},
187-
Object {
188-
"data": Object {
189-
"name": "MAKE",
190-
"type": 3,
191-
},
192-
"kind": 6,
193-
"label": "MAKE",
194-
},
195-
Object {
196-
"data": Object {
197-
"name": "make",
198-
"type": 3,
199-
},
200-
"kind": 6,
201-
"label": "make",
202-
},
203-
Object {
204-
"data": Object {
205-
"name": "clean",
206-
"type": 3,
207-
},
208-
"kind": 6,
209-
"label": "clean",
210-
},
211-
Object {
212-
"data": Object {
213-
"name": "node_version",
214-
"type": 3,
215-
},
216-
"kind": 6,
217-
"label": "node_version",
218-
},
219-
Object {
220-
"data": Object {
221-
"name": "t",
222-
"type": 3,
223-
},
224-
"kind": 6,
225-
"label": "t",
226-
},
227-
Object {
228-
"data": Object {
229-
"name": "url",
230-
"type": 3,
231-
},
232-
"kind": 6,
233-
"label": "url",
234-
},
235-
Object {
236-
"data": Object {
237-
"name": "ver",
238-
"type": 3,
239-
},
240-
"kind": 6,
241-
"label": "ver",
242-
},
243-
Object {
244-
"data": Object {
245-
"name": "isnpm10",
246-
"type": 3,
247-
},
248-
"kind": 6,
249-
"label": "isnpm10",
250-
},
251-
Object {
252-
"data": Object {
253-
"name": "NODE",
254-
"type": 3,
255-
},
256-
"kind": 6,
257-
"label": "NODE",
258-
},
259-
]
260-
`;
261-
262-
exports[`findSymbols issue 101 1`] = `
129+
exports[`findSymbolsForFile issue 101 1`] = `
263130
Array [
264131
Object {
265132
"kind": 12,
@@ -335,7 +202,7 @@ Array [
335202
]
336203
`;
337204

338-
exports[`findSymbols returns a list of SymbolInformation if uri is found 1`] = `
205+
exports[`findSymbolsForFile returns a list of SymbolInformation if uri is found 1`] = `
339206
Array [
340207
Object {
341208
"kind": 13,

server/src/__tests__/analyzer.test.ts

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,23 @@ describe('findReferences', () => {
6161
})
6262
})
6363

64-
describe('findSymbols', () => {
64+
describe('findSymbolsForFile', () => {
6565
it('returns empty list if uri is not found', () => {
6666
analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
67-
const result = analyzer.findSymbols('foobar.sh')
67+
const result = analyzer.findSymbolsForFile({ uri: 'foobar.sh' })
6868
expect(result).toEqual([])
6969
})
7070

7171
it('returns a list of SymbolInformation if uri is found', () => {
7272
analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
73-
const result = analyzer.findSymbols(CURRENT_URI)
73+
const result = analyzer.findSymbolsForFile({ uri: CURRENT_URI })
7474
expect(result).not.toEqual([])
7575
expect(result).toMatchSnapshot()
7676
})
7777

7878
it('issue 101', () => {
7979
analyzer.analyze(CURRENT_URI, FIXTURES.ISSUE101)
80-
const result = analyzer.findSymbols(CURRENT_URI)
80+
const result = analyzer.findSymbolsForFile({ uri: CURRENT_URI })
8181
expect(result).not.toEqual([])
8282
expect(result).toMatchSnapshot()
8383
})
@@ -102,9 +102,91 @@ describe('wordAtPoint', () => {
102102
})
103103

104104
describe('findSymbolCompletions', () => {
105-
it('return a list of symbols', () => {
106-
analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
107-
expect(analyzer.findSymbolCompletions(CURRENT_URI)).toMatchSnapshot()
105+
it('return a list of symbols across the workspace', () => {
106+
analyzer.analyze('install.sh', FIXTURES.INSTALL)
107+
analyzer.analyze('sourcing-sh', FIXTURES.SOURCING)
108+
109+
expect(analyzer.findSymbolsMatchingWord({ word: 'npm_config_logl' }))
110+
.toMatchInlineSnapshot(`
111+
Array [
112+
Object {
113+
"kind": 13,
114+
"location": Object {
115+
"range": Object {
116+
"end": Object {
117+
"character": 27,
118+
"line": 40,
119+
},
120+
"start": Object {
121+
"character": 0,
122+
"line": 40,
123+
},
124+
},
125+
"uri": "dummy-uri.sh",
126+
},
127+
"name": "npm_config_loglevel",
128+
},
129+
Object {
130+
"kind": 13,
131+
"location": Object {
132+
"range": Object {
133+
"end": Object {
134+
"character": 31,
135+
"line": 48,
136+
},
137+
"start": Object {
138+
"character": 2,
139+
"line": 48,
140+
},
141+
},
142+
"uri": "dummy-uri.sh",
143+
},
144+
"name": "npm_config_loglevel",
145+
},
146+
Object {
147+
"kind": 13,
148+
"location": Object {
149+
"range": Object {
150+
"end": Object {
151+
"character": 27,
152+
"line": 40,
153+
},
154+
"start": Object {
155+
"character": 0,
156+
"line": 40,
157+
},
158+
},
159+
"uri": "install.sh",
160+
},
161+
"name": "npm_config_loglevel",
162+
},
163+
Object {
164+
"kind": 13,
165+
"location": Object {
166+
"range": Object {
167+
"end": Object {
168+
"character": 31,
169+
"line": 48,
170+
},
171+
"start": Object {
172+
"character": 2,
173+
"line": 48,
174+
},
175+
},
176+
"uri": "install.sh",
177+
},
178+
"name": "npm_config_loglevel",
179+
},
180+
]
181+
`)
182+
183+
expect(analyzer.findSymbolsMatchingWord({ word: 'xxxxxxxx' })).toMatchInlineSnapshot(
184+
`Array []`,
185+
)
186+
187+
expect(analyzer.findSymbolsMatchingWord({ word: 'BLU' })).toMatchInlineSnapshot(
188+
`Array []`,
189+
)
108190
})
109191
})
110192

server/src/__tests__/server.test.ts

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ describe('server', () => {
219219
{} as any,
220220
)
221221

222-
// Limited set
222+
// Limited set (not using snapshot due to different executables on CI and locally)
223223
expect('length' in result && result.length < 5).toBe(true)
224224
expect(result).toEqual(
225225
expect.arrayContaining([
@@ -281,4 +281,102 @@ describe('server', () => {
281281

282282
expect(result).toEqual([])
283283
})
284+
285+
it('responds to onCompletion when word is found in another file', async () => {
286+
const { connection, server } = await initializeServer()
287+
server.register(connection)
288+
289+
const onCompletion = connection.onCompletion.mock.calls[0][0]
290+
291+
const resultVariable = await onCompletion(
292+
{
293+
textDocument: {
294+
uri: FIXTURE_URI.SOURCING,
295+
},
296+
position: {
297+
// $BLU (variable)
298+
line: 6,
299+
character: 7,
300+
},
301+
},
302+
{} as any,
303+
)
304+
305+
expect(resultVariable).toMatchInlineSnapshot(`
306+
Array [
307+
Object {
308+
"data": Object {
309+
"name": "BLUE",
310+
"type": 3,
311+
},
312+
"documentation": "Variable defined in ../extension.inc",
313+
"kind": 6,
314+
"label": "BLUE",
315+
},
316+
]
317+
`)
318+
319+
const resultFunction = await onCompletion(
320+
{
321+
textDocument: {
322+
uri: FIXTURE_URI.SOURCING,
323+
},
324+
position: {
325+
// add_a_us (function)
326+
line: 8,
327+
character: 7,
328+
},
329+
},
330+
{} as any,
331+
)
332+
333+
expect(resultFunction).toMatchInlineSnapshot(`
334+
Array [
335+
Object {
336+
"data": Object {
337+
"name": "add_a_user",
338+
"type": 3,
339+
},
340+
"documentation": "Function defined in ../issue101.sh",
341+
"kind": 3,
342+
"label": "add_a_user",
343+
},
344+
]
345+
`)
346+
})
347+
348+
it('responds to onCompletion with local symbol when word is found in multiple files', async () => {
349+
const { connection, server } = await initializeServer()
350+
server.register(connection)
351+
352+
const onCompletion = connection.onCompletion.mock.calls[0][0]
353+
354+
const result = await onCompletion(
355+
{
356+
textDocument: {
357+
uri: FIXTURE_URI.SOURCING,
358+
},
359+
position: {
360+
// BOL (BOLD is defined in multiple places)
361+
line: 12,
362+
character: 7,
363+
},
364+
},
365+
{} as any,
366+
)
367+
368+
expect(result).toMatchInlineSnapshot(`
369+
Array [
370+
Object {
371+
"data": Object {
372+
"name": "BOLD",
373+
"type": 3,
374+
},
375+
"documentation": undefined,
376+
"kind": 6,
377+
"label": "BOLD",
378+
},
379+
]
380+
`)
381+
})
284382
})

0 commit comments

Comments
 (0)