1
- import FIXTURES , { FIXTURE_FOLDER } from '../../../testing/fixtures'
1
+ import FIXTURES , { FIXTURE_FOLDER , FIXTURE_URI } from '../../../testing/fixtures'
2
2
import { getMockConnection } from '../../../testing/mocks'
3
3
import Analyzer from '../analyser'
4
4
import { initializeParser } from '../parser'
@@ -8,6 +8,9 @@ let analyzer: Analyzer
8
8
9
9
const CURRENT_URI = 'dummy-uri.sh'
10
10
11
+ // if you add a .sh file to testing/fixtures, update this value
12
+ const FIXTURE_FILES_MATCHING_GLOB = 11
13
+
11
14
beforeAll ( async ( ) => {
12
15
const parser = await initializeParser ( )
13
16
analyzer = new Analyzer ( parser )
@@ -33,17 +36,62 @@ describe('analyze', () => {
33
36
} )
34
37
35
38
describe ( 'findDefinition' , ( ) => {
36
- it ( 'returns empty list if parameter is not found' , ( ) => {
39
+ it ( 'returns an empty list if word is not found' , ( ) => {
37
40
analyzer . analyze ( CURRENT_URI , FIXTURES . INSTALL )
38
- const result = analyzer . findDefinition ( 'foobar' )
41
+ const result = analyzer . findDefinition ( { uri : CURRENT_URI , word : 'foobar' } )
39
42
expect ( result ) . toEqual ( [ ] )
40
43
} )
41
44
45
+ it ( 'returns a location to a file if word is the path in a sourcing statement' , ( ) => {
46
+ analyzer . analyze ( CURRENT_URI , FIXTURES . SOURCING )
47
+ const result = analyzer . findDefinition ( {
48
+ uri : CURRENT_URI ,
49
+ word : './extension.inc' ,
50
+ position : { character : 10 , line : 2 } ,
51
+ } )
52
+ expect ( result ) . toMatchInlineSnapshot ( `
53
+ Array [
54
+ Object {
55
+ "range": Object {
56
+ "end": Object {
57
+ "character": 0,
58
+ "line": 0,
59
+ },
60
+ "start": Object {
61
+ "character": 0,
62
+ "line": 0,
63
+ },
64
+ },
65
+ "uri": "extension.inc",
66
+ },
67
+ ]
68
+ ` )
69
+ } )
70
+
42
71
it ( 'returns a list of locations if parameter is found' , ( ) => {
43
72
analyzer . analyze ( CURRENT_URI , FIXTURES . INSTALL )
44
- const result = analyzer . findDefinition ( 'node_version' )
73
+ const result = analyzer . findDefinition ( {
74
+ uri : CURRENT_URI ,
75
+ word : 'node_version' ,
76
+ } )
45
77
expect ( result ) . not . toEqual ( [ ] )
46
- expect ( result ) . toMatchSnapshot ( )
78
+ expect ( result ) . toMatchInlineSnapshot ( `
79
+ Array [
80
+ Object {
81
+ "range": Object {
82
+ "end": Object {
83
+ "character": 37,
84
+ "line": 148,
85
+ },
86
+ "start": Object {
87
+ "character": 0,
88
+ "line": 148,
89
+ },
90
+ },
91
+ "uri": "dummy-uri.sh",
92
+ },
93
+ ]
94
+ ` )
47
95
} )
48
96
} )
49
97
@@ -84,6 +132,50 @@ describe('findSymbolsForFile', () => {
84
132
} )
85
133
} )
86
134
135
+ describe ( 'findAllSourcedUris' , ( ) => {
136
+ it ( 'returns references to sourced files' , async ( ) => {
137
+ const parser = await initializeParser ( )
138
+ const connection = getMockConnection ( )
139
+
140
+ const newAnalyzer = await Analyzer . fromRoot ( {
141
+ connection,
142
+ rootPath : FIXTURE_FOLDER ,
143
+ parser,
144
+ } )
145
+
146
+ const result = newAnalyzer . findAllSourcedUris ( { uri : FIXTURE_URI . SOURCING } )
147
+ expect ( result ) . toEqual (
148
+ new Set ( [
149
+ `file://${ FIXTURE_FOLDER } issue101.sh` ,
150
+ `file://${ FIXTURE_FOLDER } extension.inc` ,
151
+ ] ) ,
152
+ )
153
+ } )
154
+
155
+ it ( 'returns references to sourced files without file extension' , async ( ) => {
156
+ const parser = await initializeParser ( )
157
+ const connection = getMockConnection ( )
158
+
159
+ const newAnalyzer = await Analyzer . fromRoot ( {
160
+ connection,
161
+ rootPath : FIXTURE_FOLDER ,
162
+ parser,
163
+ } )
164
+
165
+ // Parse the file without extension
166
+ newAnalyzer . analyze ( FIXTURE_URI . MISSING_EXTENSION , FIXTURES . MISSING_EXTENSION )
167
+
168
+ const result = newAnalyzer . findAllSourcedUris ( { uri : FIXTURE_URI . MISSING_EXTENSION } )
169
+ expect ( result ) . toEqual (
170
+ new Set ( [
171
+ `file://${ FIXTURE_FOLDER } extension.inc` ,
172
+ `file://${ FIXTURE_FOLDER } issue101.sh` ,
173
+ `file://${ FIXTURE_FOLDER } sourcing.sh` ,
174
+ ] ) ,
175
+ )
176
+ } )
177
+ } )
178
+
87
179
describe ( 'wordAtPoint' , ( ) => {
88
180
it ( 'returns current word at a given point' , ( ) => {
89
181
analyzer . analyze ( CURRENT_URI , FIXTURES . INSTALL )
@@ -112,92 +204,41 @@ describe('wordAtPoint', () => {
112
204
} )
113
205
} )
114
206
115
- describe ( 'findSymbolCompletions ' , ( ) => {
207
+ describe ( 'findSymbolsMatchingWord ' , ( ) => {
116
208
it ( 'return a list of symbols across the workspace' , ( ) => {
117
209
analyzer . analyze ( 'install.sh' , FIXTURES . INSTALL )
118
210
analyzer . analyze ( 'sourcing-sh' , FIXTURES . SOURCING )
119
211
120
212
expect (
121
- analyzer . findSymbolsMatchingWord ( { word : 'npm_config_logl' , exactMatch : false } ) ,
122
- ) . toMatchInlineSnapshot ( `
123
- Array [
124
- Object {
125
- "kind": 13,
126
- "location": Object {
127
- "range": Object {
128
- "end": Object {
129
- "character": 27,
130
- "line": 40,
131
- },
132
- "start": Object {
133
- "character": 0,
134
- "line": 40,
135
- },
136
- },
137
- "uri": "dummy-uri.sh",
138
- },
139
- "name": "npm_config_loglevel",
140
- },
141
- Object {
142
- "kind": 13,
143
- "location": Object {
144
- "range": Object {
145
- "end": Object {
146
- "character": 31,
147
- "line": 48,
148
- },
149
- "start": Object {
150
- "character": 2,
151
- "line": 48,
152
- },
153
- },
154
- "uri": "dummy-uri.sh",
155
- },
156
- "name": "npm_config_loglevel",
157
- },
158
- Object {
159
- "kind": 13,
160
- "location": Object {
161
- "range": Object {
162
- "end": Object {
163
- "character": 27,
164
- "line": 40,
165
- },
166
- "start": Object {
167
- "character": 0,
168
- "line": 40,
169
- },
170
- },
171
- "uri": "install.sh",
172
- },
173
- "name": "npm_config_loglevel",
174
- },
175
- Object {
176
- "kind": 13,
177
- "location": Object {
178
- "range": Object {
179
- "end": Object {
180
- "character": 31,
181
- "line": 48,
182
- },
183
- "start": Object {
184
- "character": 2,
185
- "line": 48,
186
- },
187
- },
188
- "uri": "install.sh",
189
- },
190
- "name": "npm_config_loglevel",
191
- },
192
- ]
193
- ` )
213
+ analyzer . findSymbolsMatchingWord ( {
214
+ word : 'npm_config_logl' ,
215
+ uri : FIXTURE_URI . INSTALL ,
216
+ exactMatch : false ,
217
+ } ) ,
218
+ ) . toMatchInlineSnapshot ( `Array []` )
194
219
195
220
expect (
196
- analyzer . findSymbolsMatchingWord ( { word : 'xxxxxxxx' , exactMatch : false } ) ,
221
+ analyzer . findSymbolsMatchingWord ( {
222
+ word : 'xxxxxxxx' ,
223
+ uri : FIXTURE_URI . INSTALL ,
224
+ exactMatch : false ,
225
+ } ) ,
197
226
) . toMatchInlineSnapshot ( `Array []` )
198
227
199
228
expect (
200
- analyzer . findSymbolsMatchingWord ( { word : 'BLU' , exactMatch : false } ) ,
229
+ analyzer . findSymbolsMatchingWord ( {
230
+ word : 'BLU' ,
231
+ uri : FIXTURE_URI . INSTALL ,
232
+ exactMatch : false ,
233
+ } ) ,
234
+ ) . toMatchInlineSnapshot ( `Array []` )
235
+
236
+ expect (
237
+ analyzer . findSymbolsMatchingWord ( {
238
+ word : 'BLU' ,
239
+ uri : FIXTURE_URI . SOURCING ,
240
+ exactMatch : false ,
241
+ } ) ,
201
242
) . toMatchInlineSnapshot ( `Array []` )
202
243
} )
203
244
} )
@@ -249,9 +290,6 @@ describe('fromRoot', () => {
249
290
250
291
expect ( connection . window . showWarningMessage ) . not . toHaveBeenCalled ( )
251
292
252
- // if you add a .sh file to testing/fixtures, update this value
253
- const FIXTURE_FILES_MATCHING_GLOB = 11
254
-
255
293
// Intro, stats on glob, one file skipped due to shebang, and outro
256
294
const LOG_LINES = FIXTURE_FILES_MATCHING_GLOB + 4
257
295
0 commit comments