@@ -103,7 +103,7 @@ private async Task<SymbolReference> GetDefinition(ScriptRegion scriptRegion)
103103 return definitions . FirstOrDefault ( ) ;
104104 }
105105
106- private async Task < List < SymbolReference > > GetReferences ( ScriptRegion scriptRegion )
106+ private async Task < IEnumerable < SymbolReference > > GetReferences ( ScriptRegion scriptRegion )
107107 {
108108 ScriptFile scriptFile = GetScriptFile ( scriptRegion ) ;
109109
@@ -117,10 +117,10 @@ private async Task<List<SymbolReference>> GetReferences(ScriptRegion scriptRegio
117117 IEnumerable < SymbolReference > symbols =
118118 await symbolsService . ScanForReferencesOfSymbolAsync ( symbol ) . ConfigureAwait ( true ) ;
119119
120- return symbols . OrderBy ( i => i . ScriptRegion . ToRange ( ) . Start ) . ToList ( ) ;
120+ return symbols . OrderBy ( ( i ) => i . ScriptRegion . ToRange ( ) . Start ) . ToList ( ) ;
121121 }
122122
123- private IReadOnlyList < SymbolReference > GetOccurrences ( ScriptRegion scriptRegion )
123+ private IEnumerable < SymbolReference > GetOccurrences ( ScriptRegion scriptRegion )
124124 {
125125 return SymbolsService
126126 . FindOccurrencesInFile (
@@ -189,7 +189,7 @@ await psesHost.ExecutePSCommandAsync(
189189 [ Fact ]
190190 public async Task FindsReferencesOnFunction ( )
191191 {
192- List < SymbolReference > symbols = await GetReferences ( FindsReferencesOnFunctionData . SourceDetails ) . ConfigureAwait ( true ) ;
192+ IEnumerable < SymbolReference > symbols = await GetReferences ( FindsReferencesOnFunctionData . SourceDetails ) . ConfigureAwait ( true ) ;
193193 Assert . Collection ( symbols ,
194194 ( i ) => AssertIsRegion ( i . NameRegion , 1 , 10 , 1 , 21 ) ,
195195 ( i ) => AssertIsRegion ( i . NameRegion , 3 , 5 , 3 , 16 ) ,
@@ -204,14 +204,19 @@ await psesHost.ExecutePSCommandAsync(
204204 new PSCommand ( ) . AddScript ( "Set-Alias -Name My-Alias -Value My-Function" ) ,
205205 CancellationToken . None ) . ConfigureAwait ( true ) ;
206206
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 ) ) ,
209211 ( i ) => AssertIsRegion ( i . NameRegion , 1 , 10 , 1 , 21 ) ,
210212 ( i ) => AssertIsRegion ( i . NameRegion , 3 , 5 , 3 , 16 ) ,
211213 ( i ) => AssertIsRegion ( i . NameRegion , 10 , 1 , 10 , 12 ) ,
212214 // 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+ } ) ;
215220 }
216221
217222 [ Fact ]
@@ -242,37 +247,89 @@ public async Task FindsFunctionDefinitionInWorkspace()
242247 [ Fact ]
243248 public async Task FindsVariableDefinition ( )
244249 {
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 ) ;
249256 }
250257
251258 [ Fact ]
252259 public async Task FindsReferencesOnVariable ( )
253260 {
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+ } ) ;
258283 }
259284
260285 [ Fact ]
261286 public void FindsOccurrencesOnVariable ( )
262287 {
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+ } ) ;
267308 }
268309
269310 [ Fact ]
270311 public void FindsOccurrencesOnFunction ( )
271312 {
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+ } ) ;
276333 }
277334
278335 [ Fact ]
0 commit comments