Skip to content

Commit a86c78a

Browse files
authored
Merge pull request #649 from bash-lsp/scope-aware-symbols
Scope aware symbol resolution
2 parents bfd1ec4 + 4b4b2ce commit a86c78a

File tree

11 files changed

+1153
-695
lines changed

11 files changed

+1153
-695
lines changed

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

Lines changed: 209 additions & 222 deletions
Large diffs are not rendered by default.

server/src/__tests__/analyzer.test.ts

Lines changed: 219 additions & 63 deletions
Large diffs are not rendered by default.

server/src/__tests__/server.test.ts

Lines changed: 147 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ describe('server', () => {
221221
{} as any,
222222
)
223223

224-
// TODO: there is a superfluous range here on line 0:
225224
expect(result1).toMatchInlineSnapshot(`
226225
Array [
227226
Object {
@@ -236,18 +235,6 @@ describe('server', () => {
236235
},
237236
},
238237
},
239-
Object {
240-
"range": Object {
241-
"end": Object {
242-
"character": 12,
243-
"line": 0,
244-
},
245-
"start": Object {
246-
"character": 9,
247-
"line": 0,
248-
},
249-
},
250-
},
251238
Object {
252239
"range": Object {
253240
"end": Object {
@@ -279,6 +266,134 @@ describe('server', () => {
279266
)
280267

281268
expect(result2).toMatchInlineSnapshot(`Array []`)
269+
270+
const result3 = await onDocumentHighlight(
271+
{
272+
textDocument: {
273+
uri: FIXTURE_URI.SCOPE,
274+
},
275+
position: {
276+
// X
277+
line: 32,
278+
character: 8,
279+
},
280+
},
281+
{} as any,
282+
{} as any,
283+
)
284+
285+
expect(result3).toMatchInlineSnapshot(`
286+
Array [
287+
Object {
288+
"range": Object {
289+
"end": Object {
290+
"character": 1,
291+
"line": 2,
292+
},
293+
"start": Object {
294+
"character": 0,
295+
"line": 2,
296+
},
297+
},
298+
},
299+
Object {
300+
"range": Object {
301+
"end": Object {
302+
"character": 1,
303+
"line": 4,
304+
},
305+
"start": Object {
306+
"character": 0,
307+
"line": 4,
308+
},
309+
},
310+
},
311+
Object {
312+
"range": Object {
313+
"end": Object {
314+
"character": 9,
315+
"line": 8,
316+
},
317+
"start": Object {
318+
"character": 8,
319+
"line": 8,
320+
},
321+
},
322+
},
323+
Object {
324+
"range": Object {
325+
"end": Object {
326+
"character": 11,
327+
"line": 12,
328+
},
329+
"start": Object {
330+
"character": 10,
331+
"line": 12,
332+
},
333+
},
334+
},
335+
Object {
336+
"range": Object {
337+
"end": Object {
338+
"character": 13,
339+
"line": 15,
340+
},
341+
"start": Object {
342+
"character": 12,
343+
"line": 15,
344+
},
345+
},
346+
},
347+
Object {
348+
"range": Object {
349+
"end": Object {
350+
"character": 13,
351+
"line": 19,
352+
},
353+
"start": Object {
354+
"character": 12,
355+
"line": 19,
356+
},
357+
},
358+
},
359+
Object {
360+
"range": Object {
361+
"end": Object {
362+
"character": 15,
363+
"line": 20,
364+
},
365+
"start": Object {
366+
"character": 14,
367+
"line": 20,
368+
},
369+
},
370+
},
371+
Object {
372+
"range": Object {
373+
"end": Object {
374+
"character": 11,
375+
"line": 29,
376+
},
377+
"start": Object {
378+
"character": 10,
379+
"line": 29,
380+
},
381+
},
382+
},
383+
Object {
384+
"range": Object {
385+
"end": Object {
386+
"character": 9,
387+
"line": 32,
388+
},
389+
"start": Object {
390+
"character": 8,
391+
"line": 32,
392+
},
393+
},
394+
},
395+
]
396+
`)
282397
})
283398

284399
it('responds to onWorkspaceSymbol', async () => {
@@ -307,17 +422,6 @@ describe('server', () => {
307422
},
308423
name: 'npm_config_loglevel',
309424
},
310-
{
311-
kind: expect.any(Number),
312-
location: {
313-
range: {
314-
end: { character: 31, line: 48 },
315-
start: { character: 2, line: 48 },
316-
},
317-
uri: expect.stringContaining('/testing/fixtures/install.sh'),
318-
},
319-
name: 'npm_config_loglevel',
320-
},
321425
])
322426
}
323427

@@ -669,58 +773,6 @@ describe('server', () => {
669773
"kind": 6,
670774
"label": "RESET",
671775
},
672-
Object {
673-
"data": Object {
674-
"name": "USER",
675-
"type": 3,
676-
},
677-
"documentation": Object {
678-
"kind": "markdown",
679-
"value": "Variable: **USER** - *defined in issue101.sh*",
680-
},
681-
"kind": 6,
682-
"label": "USER",
683-
},
684-
Object {
685-
"data": Object {
686-
"name": "PASSWORD",
687-
"type": 3,
688-
},
689-
"documentation": Object {
690-
"kind": "markdown",
691-
"value": "Variable: **PASSWORD** - *defined in issue101.sh*",
692-
},
693-
"kind": 6,
694-
"label": "PASSWORD",
695-
},
696-
Object {
697-
"data": Object {
698-
"name": "COMMENTS",
699-
"type": 3,
700-
},
701-
"documentation": Object {
702-
"kind": "markdown",
703-
"value": "Variable: **COMMENTS** - *defined in issue101.sh*
704-
705-
\`\`\`txt
706-
Having shifted twice, the rest is now comments ...
707-
\`\`\`",
708-
},
709-
"kind": 6,
710-
"label": "COMMENTS",
711-
},
712-
Object {
713-
"data": Object {
714-
"name": "tag",
715-
"type": 3,
716-
},
717-
"documentation": Object {
718-
"kind": "markdown",
719-
"value": "Variable: **tag** - *defined in ../../scripts/tag-release.inc*",
720-
},
721-
"kind": 6,
722-
"label": "tag",
723-
},
724776
]
725777
`)
726778
})
@@ -849,30 +901,27 @@ describe('server', () => {
849901
`)
850902
})
851903

852-
it.failing(
853-
'returns executable documentation if the function is not redefined',
854-
async () => {
855-
const { connection, server } = await initializeServer()
856-
server.register(connection)
904+
it('returns executable documentation if the function is not redefined', async () => {
905+
const { connection, server } = await initializeServer()
906+
server.register(connection)
857907

858-
const onHover = connection.onHover.mock.calls[0][0]
908+
const onHover = connection.onHover.mock.calls[0][0]
859909

860-
const result = await onHover(
861-
{
862-
textDocument: {
863-
uri: FIXTURE_URI.OVERRIDE_SYMBOL,
864-
},
865-
position: {
866-
line: 2,
867-
character: 1,
868-
},
910+
const result = await onHover(
911+
{
912+
textDocument: {
913+
uri: FIXTURE_URI.OVERRIDE_SYMBOL,
869914
},
870-
{} as any,
871-
{} as any,
872-
)
915+
position: {
916+
line: 2,
917+
character: 1,
918+
},
919+
},
920+
{} as any,
921+
{} as any,
922+
)
873923

874-
expect(result).toBeDefined()
875-
expect((result as any)?.contents.value).toContain('ls – list directory contents')
876-
},
877-
)
924+
expect(result).toBeDefined()
925+
expect((result as any)?.contents.value).toContain('list directory contents')
926+
})
878927
})

0 commit comments

Comments
 (0)