@@ -39,8 +39,6 @@ internal class SymbolsService
3939
4040 private readonly ConcurrentDictionary < string , ICodeLensProvider > _codeLensProviders ;
4141 private readonly ConcurrentDictionary < string , IDocumentSymbolProvider > _documentSymbolProviders ;
42- private readonly Dictionary < String , List < String > > _cmdletToAliasDictionary ;
43- private readonly Dictionary < String , String > _aliasToCmdletDictionary ;
4442 #endregion
4543
4644 #region Constructors
@@ -85,10 +83,6 @@ public SymbolsService(
8583 {
8684 _documentSymbolProviders . TryAdd ( documentSymbolProvider . ProviderId , documentSymbolProvider ) ;
8785 }
88-
89- _cmdletToAliasDictionary = new Dictionary < String , List < String > > ( StringComparer . OrdinalIgnoreCase ) ;
90- _aliasToCmdletDictionary = new Dictionary < String , String > ( StringComparer . OrdinalIgnoreCase ) ;
91- GetAliases ( ) ;
9286 }
9387
9488 #endregion
@@ -191,6 +185,8 @@ public List<SymbolReference> FindReferencesOfSymbol(
191185 return null ;
192186 }
193187
188+ ( ConcurrentDictionary < string , List < string > > cmdletToAliases , ConcurrentDictionary < string , string > aliasToCmdlets ) = await CommandHelpers . GetAliasesAsync ( _executionService ) . ConfigureAwait ( false ) ;
189+
194190 // We want to look for references first in referenced files, hence we use ordered dictionary
195191 // TODO: File system case-sensitivity is based on filesystem not OS, but OS is a much cheaper heuristic
196192 var fileMap = RuntimeInformation . IsOSPlatform ( OSPlatform . Linux )
@@ -224,8 +220,8 @@ public List<SymbolReference> FindReferencesOfSymbol(
224220 IEnumerable < SymbolReference > references = AstOperations . FindReferencesOfSymbol (
225221 file . ScriptAst ,
226222 foundSymbol ,
227- _cmdletToAliasDictionary ,
228- _aliasToCmdletDictionary ) ;
223+ cmdletToAliases ,
224+ aliasToCmdlets ) ;
229225
230226 foreach ( SymbolReference reference in references )
231227 {
@@ -494,36 +490,6 @@ await CommandHelpers.GetCommandInfoAsync(
494490 return foundDefinition ;
495491 }
496492
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-
527493 /// <summary>
528494 /// Gets a path from a dot-source symbol.
529495 /// </summary>
0 commit comments