@@ -137,11 +137,6 @@ public IEnumerable<SymbolReference> FindSymbolsInFile(ScriptFile scriptFile)
137137 // asserting we should use a giant nested ternary.
138138 private static string [ ] GetIdentifiers ( string symbolName , SymbolType symbolType , CommandHelpers . AliasMap aliases )
139139 {
140- if ( symbolType is not SymbolType . Function )
141- {
142- return new [ ] { symbolName } ;
143- }
144-
145140 if ( ! aliases . CmdletToAliases . TryGetValue ( symbolName , out List < string > foundAliasList ) )
146141 {
147142 return new [ ] { symbolName } ;
@@ -165,22 +160,31 @@ public async Task<IEnumerable<SymbolReference>> ScanForReferencesOfSymbolAsync(
165160 return Enumerable . Empty < SymbolReference > ( ) ;
166161 }
167162
168- // TODO: Should we handle aliases at a lower level?
169- CommandHelpers . AliasMap aliases = await CommandHelpers . GetAliasesAsync (
170- _executionService ,
171- cancellationToken ) . ConfigureAwait ( false ) ;
163+ // We want to handle aliases for functions, but we only want to do the work of getting
164+ // the aliases when we must. We can't cache the alias list on first run else we won't
165+ // support newly defined aliases.
166+ string [ ] allIdentifiers ;
167+ if ( symbol . Type is SymbolType . Function )
168+ {
169+ CommandHelpers . AliasMap aliases = await CommandHelpers . GetAliasesAsync (
170+ _executionService ,
171+ cancellationToken ) . ConfigureAwait ( false ) ;
172172
173- string targetName = symbol . Id ;
174- if ( symbol . Type is SymbolType . Function
175- && aliases . AliasToCmdlets . TryGetValue ( symbol . Id , out string aliasDefinition ) )
173+ string targetName = symbol . Id ;
174+ if ( aliases . AliasToCmdlets . TryGetValue ( symbol . Id , out string aliasDefinition ) )
175+ {
176+ targetName = aliasDefinition ;
177+ }
178+ allIdentifiers = GetIdentifiers ( targetName , symbol . Type , aliases ) ;
179+ }
180+ else
176181 {
177- targetName = aliasDefinition ;
182+ allIdentifiers = new [ ] { symbol . Id } ;
178183 }
179184
180185 await ScanWorkspacePSFiles ( cancellationToken ) . ConfigureAwait ( false ) ;
181186
182187 List < SymbolReference > symbols = new ( ) ;
183- string [ ] allIdentifiers = GetIdentifiers ( targetName , symbol . Type , aliases ) ;
184188
185189 foreach ( ScriptFile file in _workspaceService . GetOpenedFiles ( ) )
186190 {
0 commit comments