@@ -39,7 +39,8 @@ internal class SymbolsService
39
39
40
40
private readonly ConcurrentDictionary < string , ICodeLensProvider > _codeLensProviders ;
41
41
private readonly ConcurrentDictionary < string , IDocumentSymbolProvider > _documentSymbolProviders ;
42
-
42
+ private readonly Dictionary < String , List < String > > _cmdletToAliasDictionary ;
43
+ private readonly Dictionary < String , String > _aliasToCmdletDictionary ;
43
44
#endregion
44
45
45
46
#region Constructors
@@ -84,6 +85,10 @@ public SymbolsService(
84
85
{
85
86
_documentSymbolProviders . TryAdd ( documentSymbolProvider . ProviderId , documentSymbolProvider ) ;
86
87
}
88
+
89
+ _cmdletToAliasDictionary = new Dictionary < String , List < String > > ( StringComparer . OrdinalIgnoreCase ) ;
90
+ _aliasToCmdletDictionary = new Dictionary < String , String > ( StringComparer . OrdinalIgnoreCase ) ;
91
+ GetAliases ( ) ;
87
92
}
88
93
89
94
#endregion
@@ -186,8 +191,6 @@ public List<SymbolReference> FindReferencesOfSymbol(
186
191
return null ;
187
192
}
188
193
189
- // NOTE: we use to make sure aliases were loaded but took it out because we needed the pipeline thread.
190
-
191
194
// We want to look for references first in referenced files, hence we use ordered dictionary
192
195
// TODO: File system case-sensitivity is based on filesystem not OS, but OS is a much cheaper heuristic
193
196
var fileMap = RuntimeInformation . IsOSPlatform ( OSPlatform . Linux )
@@ -221,7 +224,8 @@ public List<SymbolReference> FindReferencesOfSymbol(
221
224
IEnumerable < SymbolReference > references = AstOperations . FindReferencesOfSymbol (
222
225
file . ScriptAst ,
223
226
foundSymbol ,
224
- needsAliases : false ) ;
227
+ _cmdletToAliasDictionary ,
228
+ _aliasToCmdletDictionary ) ;
225
229
226
230
foreach ( SymbolReference reference in references )
227
231
{
@@ -490,6 +494,36 @@ await CommandHelpers.GetCommandInfoAsync(
490
494
return foundDefinition ;
491
495
}
492
496
497
+ /// <summary>
498
+ /// Gets all aliases found in the runspace
499
+ /// </summary>
500
+ private async void GetAliases ( )
501
+ {
502
+ IEnumerable < CommandInfo > aliases = await _executionService . ExecuteDelegateAsync < IEnumerable < CommandInfo > > (
503
+ nameof ( GetAliases ) ,
504
+ PowerShell . Execution . ExecutionOptions . Default ,
505
+ ( pwsh , _ ) =>
506
+ {
507
+ CommandInvocationIntrinsics invokeCommand = pwsh . Runspace . SessionStateProxy . InvokeCommand ;
508
+ return invokeCommand . GetCommands ( "*" , CommandTypes . Alias , nameIsPattern : true ) ;
509
+ } ,
510
+ System . Threading . CancellationToken . None ) . ConfigureAwait ( false ) ;
511
+
512
+ foreach ( AliasInfo aliasInfo in aliases )
513
+ {
514
+ if ( ! _cmdletToAliasDictionary . ContainsKey ( aliasInfo . Definition ) )
515
+ {
516
+ _cmdletToAliasDictionary . Add ( aliasInfo . Definition , new List < String > ( ) { aliasInfo . Name } ) ;
517
+ }
518
+ else
519
+ {
520
+ _cmdletToAliasDictionary [ aliasInfo . Definition ] . Add ( aliasInfo . Name ) ;
521
+ }
522
+
523
+ _aliasToCmdletDictionary . Add ( aliasInfo . Name , aliasInfo . Definition ) ;
524
+ }
525
+ }
526
+
493
527
/// <summary>
494
528
/// Gets a path from a dot-source symbol.
495
529
/// </summary>
0 commit comments