Skip to content

Commit 8b45785

Browse files
committed
Add failing test case
#515
1 parent 2effa52 commit 8b45785

File tree

4 files changed

+33
-21
lines changed

4 files changed

+33
-21
lines changed

server/src/__tests__/analyzer.test.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ describe('findDeclarationLocations', () => {
164164
"range": Object {
165165
"end": Object {
166166
"character": 17,
167-
"line": 11,
167+
"line": 12,
168168
},
169169
"start": Object {
170170
"character": 10,
171-
"line": 11,
171+
"line": 12,
172172
},
173173
},
174174
"uri": "file://${FIXTURE_FOLDER}scope.sh",
@@ -540,11 +540,11 @@ describe('findDeclarationsMatchingWord', () => {
540540
"range": Object {
541541
"end": Object {
542542
"character": 17,
543-
"line": 11,
543+
"line": 12,
544544
},
545545
"start": Object {
546546
"character": 10,
547-
"line": 11,
547+
"line": 12,
548548
},
549549
},
550550
"uri": "file://${FIXTURE_FOLDER}scope.sh",
@@ -555,7 +555,7 @@ describe('findDeclarationsMatchingWord', () => {
555555
`)
556556

557557
// Local function definition
558-
expect(findWordFromLine('f', 20)).toMatchInlineSnapshot(`
558+
expect(findWordFromLine('f', 23)).toMatchInlineSnapshot(`
559559
Array [
560560
Object {
561561
"containerName": "g",
@@ -564,11 +564,11 @@ describe('findDeclarationsMatchingWord', () => {
564564
"range": Object {
565565
"end": Object {
566566
"character": 5,
567-
"line": 18,
567+
"line": 21,
568568
},
569569
"start": Object {
570570
"character": 4,
571-
"line": 15,
571+
"line": 18,
572572
},
573573
},
574574
"uri": "file://${FIXTURE_FOLDER}scope.sh",
@@ -609,7 +609,7 @@ describe('findDeclarationsMatchingWord', () => {
609609
"range": Object {
610610
"end": Object {
611611
"character": 1,
612-
"line": 26,
612+
"line": 30,
613613
},
614614
"start": Object {
615615
"character": 0,
@@ -622,6 +622,9 @@ describe('findDeclarationsMatchingWord', () => {
622622
},
623623
]
624624
`)
625+
626+
// FIXME: this should return the a reference to the function
627+
expect(findWordFromLine('GLOBAL_1', 1000)).toHaveLength(1)
625628
})
626629
})
627630

server/src/__tests__/server.test.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ describe('server', () => {
274274
},
275275
position: {
276276
// X
277-
line: 28,
277+
line: 32,
278278
character: 8,
279279
},
280280
},
@@ -324,71 +324,71 @@ describe('server', () => {
324324
"range": Object {
325325
"end": Object {
326326
"character": 11,
327-
"line": 11,
327+
"line": 12,
328328
},
329329
"start": Object {
330330
"character": 10,
331-
"line": 11,
331+
"line": 12,
332332
},
333333
},
334334
},
335335
Object {
336336
"range": Object {
337337
"end": Object {
338338
"character": 13,
339-
"line": 12,
339+
"line": 15,
340340
},
341341
"start": Object {
342342
"character": 12,
343-
"line": 12,
343+
"line": 15,
344344
},
345345
},
346346
},
347347
Object {
348348
"range": Object {
349349
"end": Object {
350350
"character": 13,
351-
"line": 16,
351+
"line": 19,
352352
},
353353
"start": Object {
354354
"character": 12,
355-
"line": 16,
355+
"line": 19,
356356
},
357357
},
358358
},
359359
Object {
360360
"range": Object {
361361
"end": Object {
362362
"character": 15,
363-
"line": 17,
363+
"line": 20,
364364
},
365365
"start": Object {
366366
"character": 14,
367-
"line": 17,
367+
"line": 20,
368368
},
369369
},
370370
},
371371
Object {
372372
"range": Object {
373373
"end": Object {
374374
"character": 11,
375-
"line": 25,
375+
"line": 29,
376376
},
377377
"start": Object {
378378
"character": 10,
379-
"line": 25,
379+
"line": 29,
380380
},
381381
},
382382
},
383383
Object {
384384
"range": Object {
385385
"end": Object {
386386
"character": 9,
387-
"line": 28,
387+
"line": 32,
388388
},
389389
"start": Object {
390390
"character": 8,
391-
"line": 28,
391+
"line": 32,
392392
},
393393
},
394394
},

server/src/util/declarations.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ export function getAllDeclarationsInTree({
9494
* Done by traversing the tree upwards (which is a simplification for
9595
* actual bash behaviour but deemed good enough, compared to the complexity of flow tracing).
9696
* Filters out duplicate definitions. Used when getting declarations for the current scope.
97+
*
98+
* FIXME: unfortunately this doesn't capture all global variables defined inside functions.
99+
* Wondering if getGlobalDeclarations should return this or we should make that a custom feature of this function.
97100
*/
98101
export function getLocalDeclarations({
99102
node,

testing/fixtures/scope.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ X="Mouse"
77
# some function
88
f() (
99
local X="Dog"
10+
GLOBAL_1="Global 1"
1011

1112
g() {
1213
local X="Cat"
14+
GLOBAL_1="Global 1"
15+
GLOBAL_2="Global 1"
1316
echo "${X}"
1417

1518
# another function function
@@ -23,8 +26,11 @@ f() (
2326

2427
g
2528

29+
echo "${GLOBAL_1}"
2630
echo "${X}"
2731
)
2832

2933
echo "${X}"
3034
f
35+
36+
echo "${GLOBAL_2}"

0 commit comments

Comments
 (0)