|
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 { getDefaultConfiguration } from '../config'
|
@@ -42,15 +42,60 @@ describe('analyze', () => {
|
42 | 42 | describe('findDefinition', () => {
|
43 | 43 | it('returns an empty list if word is not found', () => {
|
44 | 44 | analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
|
45 |
| - const result = analyzer.findDefinition({ word: 'foobar' }) |
| 45 | + const result = analyzer.findDefinition({ uri: CURRENT_URI, word: 'foobar' }) |
46 | 46 | expect(result).toEqual([])
|
47 | 47 | })
|
48 | 48 |
|
| 49 | + it('returns a location to a file if word is the path in a sourcing statement', () => { |
| 50 | + analyzer.analyze(CURRENT_URI, FIXTURES.SOURCING) |
| 51 | + const result = analyzer.findDefinition({ |
| 52 | + uri: CURRENT_URI, |
| 53 | + word: './extension.inc', |
| 54 | + position: { character: 10, line: 2 }, |
| 55 | + }) |
| 56 | + expect(result).toMatchInlineSnapshot(` |
| 57 | + Array [ |
| 58 | + Object { |
| 59 | + "range": Object { |
| 60 | + "end": Object { |
| 61 | + "character": 0, |
| 62 | + "line": 0, |
| 63 | + }, |
| 64 | + "start": Object { |
| 65 | + "character": 0, |
| 66 | + "line": 0, |
| 67 | + }, |
| 68 | + }, |
| 69 | + "uri": "extension.inc", |
| 70 | + }, |
| 71 | + ] |
| 72 | + `) |
| 73 | + }) |
| 74 | + |
49 | 75 | it('returns a list of locations if parameter is found', () => {
|
50 | 76 | analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
|
51 |
| - const result = analyzer.findDefinition({ word: 'node_version' }) |
| 77 | + const result = analyzer.findDefinition({ |
| 78 | + uri: CURRENT_URI, |
| 79 | + word: 'node_version', |
| 80 | + }) |
52 | 81 | expect(result).not.toEqual([])
|
53 |
| - expect(result).toMatchSnapshot() |
| 82 | + expect(result).toMatchInlineSnapshot(` |
| 83 | + Array [ |
| 84 | + Object { |
| 85 | + "range": Object { |
| 86 | + "end": Object { |
| 87 | + "character": 37, |
| 88 | + "line": 148, |
| 89 | + }, |
| 90 | + "start": Object { |
| 91 | + "character": 0, |
| 92 | + "line": 148, |
| 93 | + }, |
| 94 | + }, |
| 95 | + "uri": "dummy-uri.sh", |
| 96 | + }, |
| 97 | + ] |
| 98 | + `) |
54 | 99 | })
|
55 | 100 | })
|
56 | 101 |
|
@@ -91,6 +136,52 @@ describe('findSymbolsForFile', () => {
|
91 | 136 | })
|
92 | 137 | })
|
93 | 138 |
|
| 139 | +describe('findAllSourcedUris', () => { |
| 140 | + it('returns references to sourced files', async () => { |
| 141 | + const parser = await initializeParser() |
| 142 | + const connection = getMockConnection() |
| 143 | + |
| 144 | + const newAnalyzer = new Analyzer({ console: connection.console, parser }) |
| 145 | + await newAnalyzer.initiateBackgroundAnalysis({ |
| 146 | + backgroundAnalysisMaxFiles: defaultConfig.backgroundAnalysisMaxFiles, |
| 147 | + globPattern: defaultConfig.globPattern, |
| 148 | + rootPath: FIXTURE_FOLDER, |
| 149 | + }) |
| 150 | + |
| 151 | + const result = newAnalyzer.findAllSourcedUris({ uri: FIXTURE_URI.SOURCING }) |
| 152 | + expect(result).toEqual( |
| 153 | + new Set([ |
| 154 | + `file://${FIXTURE_FOLDER}issue101.sh`, |
| 155 | + `file://${FIXTURE_FOLDER}extension.inc`, |
| 156 | + ]), |
| 157 | + ) |
| 158 | + }) |
| 159 | + |
| 160 | + it('returns references to sourced files without file extension', async () => { |
| 161 | + const parser = await initializeParser() |
| 162 | + const connection = getMockConnection() |
| 163 | + |
| 164 | + const newAnalyzer = new Analyzer({ console: connection.console, parser }) |
| 165 | + await newAnalyzer.initiateBackgroundAnalysis({ |
| 166 | + backgroundAnalysisMaxFiles: defaultConfig.backgroundAnalysisMaxFiles, |
| 167 | + globPattern: defaultConfig.globPattern, |
| 168 | + rootPath: FIXTURE_FOLDER, |
| 169 | + }) |
| 170 | + |
| 171 | + // Parse the file without extension |
| 172 | + newAnalyzer.analyze(FIXTURE_URI.MISSING_EXTENSION, FIXTURES.MISSING_EXTENSION) |
| 173 | + |
| 174 | + const result = newAnalyzer.findAllSourcedUris({ uri: FIXTURE_URI.MISSING_EXTENSION }) |
| 175 | + expect(result).toEqual( |
| 176 | + new Set([ |
| 177 | + `file://${FIXTURE_FOLDER}extension.inc`, |
| 178 | + `file://${FIXTURE_FOLDER}issue101.sh`, |
| 179 | + `file://${FIXTURE_FOLDER}sourcing.sh`, |
| 180 | + ]), |
| 181 | + ) |
| 182 | + }) |
| 183 | +}) |
| 184 | + |
94 | 185 | describe('wordAtPoint', () => {
|
95 | 186 | it('returns current word at a given point', () => {
|
96 | 187 | analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
|
@@ -137,92 +228,41 @@ describe('commandNameAtPoint', () => {
|
137 | 228 | })
|
138 | 229 | })
|
139 | 230 |
|
140 |
| -describe('findSymbolCompletions', () => { |
| 231 | +describe('findSymbolsMatchingWord', () => { |
141 | 232 | it('return a list of symbols across the workspace', () => {
|
142 | 233 | analyzer.analyze('install.sh', FIXTURES.INSTALL)
|
143 | 234 | analyzer.analyze('sourcing-sh', FIXTURES.SOURCING)
|
144 | 235 |
|
145 | 236 | expect(
|
146 |
| - analyzer.findSymbolsMatchingWord({ word: 'npm_config_logl', exactMatch: false }), |
147 |
| - ).toMatchInlineSnapshot(` |
148 |
| - Array [ |
149 |
| - Object { |
150 |
| - "kind": 13, |
151 |
| - "location": Object { |
152 |
| - "range": Object { |
153 |
| - "end": Object { |
154 |
| - "character": 27, |
155 |
| - "line": 40, |
156 |
| - }, |
157 |
| - "start": Object { |
158 |
| - "character": 0, |
159 |
| - "line": 40, |
160 |
| - }, |
161 |
| - }, |
162 |
| - "uri": "dummy-uri.sh", |
163 |
| - }, |
164 |
| - "name": "npm_config_loglevel", |
165 |
| - }, |
166 |
| - Object { |
167 |
| - "kind": 13, |
168 |
| - "location": Object { |
169 |
| - "range": Object { |
170 |
| - "end": Object { |
171 |
| - "character": 31, |
172 |
| - "line": 48, |
173 |
| - }, |
174 |
| - "start": Object { |
175 |
| - "character": 2, |
176 |
| - "line": 48, |
177 |
| - }, |
178 |
| - }, |
179 |
| - "uri": "dummy-uri.sh", |
180 |
| - }, |
181 |
| - "name": "npm_config_loglevel", |
182 |
| - }, |
183 |
| - Object { |
184 |
| - "kind": 13, |
185 |
| - "location": Object { |
186 |
| - "range": Object { |
187 |
| - "end": Object { |
188 |
| - "character": 27, |
189 |
| - "line": 40, |
190 |
| - }, |
191 |
| - "start": Object { |
192 |
| - "character": 0, |
193 |
| - "line": 40, |
194 |
| - }, |
195 |
| - }, |
196 |
| - "uri": "install.sh", |
197 |
| - }, |
198 |
| - "name": "npm_config_loglevel", |
199 |
| - }, |
200 |
| - Object { |
201 |
| - "kind": 13, |
202 |
| - "location": Object { |
203 |
| - "range": Object { |
204 |
| - "end": Object { |
205 |
| - "character": 31, |
206 |
| - "line": 48, |
207 |
| - }, |
208 |
| - "start": Object { |
209 |
| - "character": 2, |
210 |
| - "line": 48, |
211 |
| - }, |
212 |
| - }, |
213 |
| - "uri": "install.sh", |
214 |
| - }, |
215 |
| - "name": "npm_config_loglevel", |
216 |
| - }, |
217 |
| - ] |
218 |
| - `) |
| 237 | + analyzer.findSymbolsMatchingWord({ |
| 238 | + word: 'npm_config_logl', |
| 239 | + uri: FIXTURE_URI.INSTALL, |
| 240 | + exactMatch: false, |
| 241 | + }), |
| 242 | + ).toMatchInlineSnapshot(`Array []`) |
| 243 | + |
| 244 | + expect( |
| 245 | + analyzer.findSymbolsMatchingWord({ |
| 246 | + word: 'xxxxxxxx', |
| 247 | + uri: FIXTURE_URI.INSTALL, |
| 248 | + exactMatch: false, |
| 249 | + }), |
| 250 | + ).toMatchInlineSnapshot(`Array []`) |
219 | 251 |
|
220 | 252 | expect(
|
221 |
| - analyzer.findSymbolsMatchingWord({ word: 'xxxxxxxx', exactMatch: false }), |
| 253 | + analyzer.findSymbolsMatchingWord({ |
| 254 | + word: 'BLU', |
| 255 | + uri: FIXTURE_URI.INSTALL, |
| 256 | + exactMatch: false, |
| 257 | + }), |
222 | 258 | ).toMatchInlineSnapshot(`Array []`)
|
223 | 259 |
|
224 | 260 | expect(
|
225 |
| - analyzer.findSymbolsMatchingWord({ word: 'BLU', exactMatch: false }), |
| 261 | + analyzer.findSymbolsMatchingWord({ |
| 262 | + word: 'BLU', |
| 263 | + uri: FIXTURE_URI.SOURCING, |
| 264 | + exactMatch: false, |
| 265 | + }), |
226 | 266 | ).toMatchInlineSnapshot(`Array []`)
|
227 | 267 | })
|
228 | 268 | })
|
|
0 commit comments