@@ -103,7 +103,7 @@ private async Task<SymbolReference> GetDefinition(ScriptRegion scriptRegion)
103
103
return definitions . FirstOrDefault ( ) ;
104
104
}
105
105
106
- private async Task < List < SymbolReference > > GetReferences ( ScriptRegion scriptRegion )
106
+ private async Task < IEnumerable < SymbolReference > > GetReferences ( ScriptRegion scriptRegion )
107
107
{
108
108
ScriptFile scriptFile = GetScriptFile ( scriptRegion ) ;
109
109
@@ -117,10 +117,10 @@ private async Task<List<SymbolReference>> GetReferences(ScriptRegion scriptRegio
117
117
IEnumerable < SymbolReference > symbols =
118
118
await symbolsService . ScanForReferencesOfSymbolAsync ( symbol ) . ConfigureAwait ( true ) ;
119
119
120
- return symbols . OrderBy ( i => i . ScriptRegion . ToRange ( ) . Start ) . ToList ( ) ;
120
+ return symbols . OrderBy ( ( i ) => i . ScriptRegion . ToRange ( ) . Start ) . ToList ( ) ;
121
121
}
122
122
123
- private IReadOnlyList < SymbolReference > GetOccurrences ( ScriptRegion scriptRegion )
123
+ private IEnumerable < SymbolReference > GetOccurrences ( ScriptRegion scriptRegion )
124
124
{
125
125
return SymbolsService
126
126
. FindOccurrencesInFile (
@@ -189,7 +189,7 @@ await psesHost.ExecutePSCommandAsync(
189
189
[ Fact ]
190
190
public async Task FindsReferencesOnFunction ( )
191
191
{
192
- List < SymbolReference > symbols = await GetReferences ( FindsReferencesOnFunctionData . SourceDetails ) . ConfigureAwait ( true ) ;
192
+ IEnumerable < SymbolReference > symbols = await GetReferences ( FindsReferencesOnFunctionData . SourceDetails ) . ConfigureAwait ( true ) ;
193
193
Assert . Collection ( symbols ,
194
194
( i ) => AssertIsRegion ( i . NameRegion , 1 , 10 , 1 , 21 ) ,
195
195
( i ) => AssertIsRegion ( i . NameRegion , 3 , 5 , 3 , 16 ) ,
@@ -204,14 +204,19 @@ await psesHost.ExecutePSCommandAsync(
204
204
new PSCommand ( ) . AddScript ( "Set-Alias -Name My-Alias -Value My-Function" ) ,
205
205
CancellationToken . None ) . ConfigureAwait ( true ) ;
206
206
207
- List < SymbolReference > symbols = await GetReferences ( FindsReferencesOnFunctionData . SourceDetails ) . ConfigureAwait ( true ) ;
208
- Assert . Collection ( symbols ,
207
+ IEnumerable < SymbolReference > symbols = await GetReferences ( FindsReferencesOnFunctionData . SourceDetails ) . ConfigureAwait ( true ) ;
208
+ Assert . Equal ( 9 , symbols . Count ( ) ) ;
209
+
210
+ Assert . Collection ( symbols . Where ( ( i ) => i . FilePath . EndsWith ( FindsReferencesOnFunctionData . SourceDetails . File ) ) ,
209
211
( i ) => AssertIsRegion ( i . NameRegion , 1 , 10 , 1 , 21 ) ,
210
212
( i ) => AssertIsRegion ( i . NameRegion , 3 , 5 , 3 , 16 ) ,
211
213
( i ) => AssertIsRegion ( i . NameRegion , 10 , 1 , 10 , 12 ) ,
212
214
// The alias.
213
- ( i ) => AssertIsRegion ( i . NameRegion , 20 , 1 , 20 , 9 ) ) ;
214
- Assert . Equal ( "My-Alias" , symbols [ 3 ] . SymbolName ) ;
215
+ ( i ) =>
216
+ {
217
+ AssertIsRegion ( i . NameRegion , 20 , 1 , 20 , 9 ) ;
218
+ Assert . Equal ( "My-Alias" , i . SymbolName ) ;
219
+ } ) ;
215
220
}
216
221
217
222
[ Fact ]
@@ -242,37 +247,89 @@ public async Task FindsFunctionDefinitionInWorkspace()
242
247
[ Fact ]
243
248
public async Task FindsVariableDefinition ( )
244
249
{
245
- SymbolReference definitionResult = await GetDefinition ( FindsVariableDefinitionData . SourceDetails ) . ConfigureAwait ( true ) ;
246
- Assert . Equal ( 6 , definitionResult . ScriptRegion . StartLineNumber ) ;
247
- Assert . Equal ( 1 , definitionResult . ScriptRegion . StartColumnNumber ) ;
248
- Assert . Equal ( "$things" , definitionResult . SymbolName ) ;
250
+ SymbolReference symbol = await GetDefinition ( FindsVariableDefinitionData . SourceDetails ) . ConfigureAwait ( true ) ;
251
+ Assert . Equal ( "$things" , symbol . SymbolName ) ;
252
+ Assert . Equal ( "$things" , symbol . DisplayString ) ;
253
+ Assert . Equal ( SymbolType . Variable , symbol . SymbolType ) ;
254
+ Assert . True ( symbol . IsDeclaration ) ;
255
+ AssertIsRegion ( symbol . NameRegion , 6 , 1 , 6 , 8 ) ;
249
256
}
250
257
251
258
[ Fact ]
252
259
public async Task FindsReferencesOnVariable ( )
253
260
{
254
- List < SymbolReference > referencesResult = await GetReferences ( FindsReferencesOnVariableData . SourceDetails ) . ConfigureAwait ( true ) ;
255
- Assert . Equal ( 3 , referencesResult . Count ) ;
256
- Assert . Equal ( 10 , referencesResult [ referencesResult . Count - 1 ] . ScriptRegion . StartLineNumber ) ;
257
- Assert . Equal ( 13 , referencesResult [ referencesResult . Count - 1 ] . ScriptRegion . StartColumnNumber ) ;
261
+ // TODO: Technically this also finds references in the workspace, but since there aren't
262
+ // any, it's identical to the test below.
263
+ IEnumerable < SymbolReference > symbols = await GetReferences ( FindsReferencesOnVariableData . SourceDetails ) . ConfigureAwait ( true ) ;
264
+ Assert . Collection ( symbols ,
265
+ ( i ) =>
266
+ {
267
+ Assert . Equal ( "$things" , i . SymbolName ) ;
268
+ Assert . Equal ( SymbolType . Variable , i . SymbolType ) ;
269
+ Assert . True ( i . IsDeclaration ) ;
270
+ } ,
271
+ ( i ) =>
272
+ {
273
+ Assert . Equal ( "$things" , i . SymbolName ) ;
274
+ Assert . Equal ( SymbolType . Variable , i . SymbolType ) ;
275
+ Assert . False ( i . IsDeclaration ) ;
276
+ } ,
277
+ ( i ) =>
278
+ {
279
+ Assert . Equal ( "$things" , i . SymbolName ) ;
280
+ Assert . Equal ( SymbolType . Variable , i . SymbolType ) ;
281
+ Assert . False ( i . IsDeclaration ) ;
282
+ } ) ;
258
283
}
259
284
260
285
[ Fact ]
261
286
public void FindsOccurrencesOnVariable ( )
262
287
{
263
- IReadOnlyList < SymbolReference > occurrencesResult = GetOccurrences ( FindsOccurrencesOnVariableData . SourceDetails ) ;
264
- Assert . Equal ( 3 , occurrencesResult . Count ) ;
265
- Assert . Equal ( 10 , occurrencesResult [ occurrencesResult . Count - 1 ] . ScriptRegion . StartLineNumber ) ;
266
- Assert . Equal ( 13 , occurrencesResult [ occurrencesResult . Count - 1 ] . ScriptRegion . StartColumnNumber ) ;
288
+ IEnumerable < SymbolReference > symbols = GetOccurrences ( FindsOccurrencesOnVariableData . SourceDetails ) ;
289
+ Assert . Collection ( symbols ,
290
+ ( i ) =>
291
+ {
292
+ Assert . Equal ( "$things" , i . SymbolName ) ;
293
+ Assert . Equal ( SymbolType . Variable , i . SymbolType ) ;
294
+ Assert . True ( i . IsDeclaration ) ;
295
+ } ,
296
+ ( i ) =>
297
+ {
298
+ Assert . Equal ( "$things" , i . SymbolName ) ;
299
+ Assert . Equal ( SymbolType . Variable , i . SymbolType ) ;
300
+ Assert . False ( i . IsDeclaration ) ;
301
+ } ,
302
+ ( i ) =>
303
+ {
304
+ Assert . Equal ( "$things" , i . SymbolName ) ;
305
+ Assert . Equal ( SymbolType . Variable , i . SymbolType ) ;
306
+ Assert . False ( i . IsDeclaration ) ;
307
+ } ) ;
267
308
}
268
309
269
310
[ Fact ]
270
311
public void FindsOccurrencesOnFunction ( )
271
312
{
272
- IReadOnlyList < SymbolReference > occurrencesResult = GetOccurrences ( FindsOccurrencesOnFunctionData . SourceDetails ) ;
273
- Assert . Equal ( 3 , occurrencesResult . Count ) ;
274
- Assert . Equal ( 10 , occurrencesResult [ occurrencesResult . Count - 1 ] . ScriptRegion . StartLineNumber ) ;
275
- Assert . Equal ( 1 , occurrencesResult [ occurrencesResult . Count - 1 ] . ScriptRegion . StartColumnNumber ) ;
313
+ IEnumerable < SymbolReference > symbols = GetOccurrences ( FindsOccurrencesOnFunctionData . SourceDetails ) ;
314
+ Assert . Collection ( symbols ,
315
+ ( i ) =>
316
+ {
317
+ Assert . Equal ( "My-Function" , i . SymbolName ) ;
318
+ Assert . Equal ( SymbolType . Function , i . SymbolType ) ;
319
+ Assert . True ( i . IsDeclaration ) ;
320
+ } ,
321
+ ( i ) =>
322
+ {
323
+ Assert . Equal ( "My-Function" , i . SymbolName ) ;
324
+ Assert . Equal ( SymbolType . Function , i . SymbolType ) ;
325
+ Assert . False ( i . IsDeclaration ) ;
326
+ } ,
327
+ ( i ) =>
328
+ {
329
+ Assert . Equal ( "My-Function" , i . SymbolName ) ;
330
+ Assert . Equal ( SymbolType . Function , i . SymbolType ) ;
331
+ Assert . False ( i . IsDeclaration ) ;
332
+ } ) ;
276
333
}
277
334
278
335
[ Fact ]
0 commit comments