@@ -188,14 +188,7 @@ public async Task<IEnumerable<SymbolReference>> ScanForReferencesOfSymbolAsync(
188
188
{
189
189
await Task . Yield ( ) ;
190
190
cancellationToken . ThrowIfCancellationRequested ( ) ;
191
-
192
- _ = file . References . TryGetReferences ( targetIdentifier , out ConcurrentBag < SymbolReference > ? references ) ;
193
- if ( references is null )
194
- {
195
- continue ;
196
- }
197
-
198
- symbols . AddRange ( references ) ;
191
+ symbols . AddRange ( file . References . TryGetReferences ( symbol with { SymbolName = targetIdentifier } ) ) ;
199
192
}
200
193
}
201
194
@@ -205,19 +198,10 @@ public async Task<IEnumerable<SymbolReference>> ScanForReferencesOfSymbolAsync(
205
198
/// <summary>
206
199
/// Finds all the occurrences of a symbol in the script given a file location.
207
200
/// </summary>
208
- public static IEnumerable < SymbolReference > ? FindOccurrencesInFile (
209
- ScriptFile scriptFile , int line , int column )
210
- {
211
- SymbolReference ? symbol = FindSymbolAtLocation ( scriptFile , line , column ) ;
212
-
213
- if ( symbol is null )
214
- {
215
- return null ;
216
- }
217
-
218
- scriptFile . References . TryGetReferences ( symbol . SymbolName , out ConcurrentBag < SymbolReference > ? references ) ;
219
- return references ;
220
- }
201
+ public static IEnumerable < SymbolReference > FindOccurrencesInFile (
202
+ ScriptFile scriptFile , int line , int column ) => scriptFile
203
+ . References
204
+ . TryGetReferences ( FindSymbolAtLocation ( scriptFile , line , column ) ) ;
221
205
222
206
/// <summary>
223
207
/// Finds the symbol at the location and returns it if it's a declaration.
@@ -236,15 +220,9 @@ public async Task<IEnumerable<SymbolReference>> ScanForReferencesOfSymbolAsync(
236
220
ScriptFile scriptFile , int line , int column )
237
221
{
238
222
SymbolReference ? symbol = FindSymbolAtLocation ( scriptFile , line , column ) ;
239
- if ( symbol is null )
240
- {
241
- return Task . FromResult < SymbolDetails ? > ( null ) ;
242
- }
243
-
244
- return SymbolDetails . CreateAsync (
245
- symbol ,
246
- _runspaceContext . CurrentRunspace ,
247
- _executionService ) ;
223
+ return symbol is null
224
+ ? Task . FromResult < SymbolDetails ? > ( null )
225
+ : SymbolDetails . CreateAsync ( symbol , _runspaceContext . CurrentRunspace , _executionService ) ;
248
226
}
249
227
250
228
/// <summary>
@@ -310,34 +288,18 @@ public async Task<IEnumerable<SymbolReference>> GetDefinitionOfSymbolAsync(
310
288
CancellationToken cancellationToken = default )
311
289
{
312
290
List < SymbolReference > declarations = new ( ) ;
313
- _ = scriptFile . References . TryGetReferences ( symbol . SymbolName , out ConcurrentBag < SymbolReference > ? symbols ) ;
314
- if ( symbols is not null )
315
- {
316
- foreach ( SymbolReference foundReference in symbols )
317
- {
318
- if ( foundReference . IsDeclaration )
319
- {
320
- _logger . LogDebug ( $ "Found possible declaration in same file ${ foundReference } ") ;
321
- declarations . Add ( foundReference ) ;
322
- }
323
- }
324
- }
325
-
291
+ declarations . AddRange ( scriptFile . References . TryGetReferences ( symbol ) . Where ( i => i . IsDeclaration ) ) ;
326
292
if ( declarations . Any ( ) )
327
293
{
294
+ _logger . LogDebug ( $ "Found possible declaration in same file ${ declarations } ") ;
328
295
return declarations ;
329
296
}
330
297
331
- foreach ( SymbolReference foundReference in await ScanForReferencesOfSymbolAsync (
332
- symbol , cancellationToken ) . ConfigureAwait ( false ) )
333
- {
334
- if ( foundReference . IsDeclaration )
335
- {
336
- _logger . LogDebug ( $ "Found possible declaration in workspace ${ foundReference } ") ;
337
- declarations . Add ( foundReference ) ;
338
- }
339
- }
298
+ IEnumerable < SymbolReference > references =
299
+ await ScanForReferencesOfSymbolAsync ( symbol , cancellationToken ) . ConfigureAwait ( false ) ;
300
+ declarations . AddRange ( references . Where ( i => i . IsDeclaration ) ) ;
340
301
302
+ _logger . LogDebug ( $ "Found possible declaration in workspace ${ declarations } ") ;
341
303
return declarations ;
342
304
}
343
305
0 commit comments