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