@@ -137,11 +137,6 @@ public IEnumerable<SymbolReference> FindSymbolsInFile(ScriptFile scriptFile)
137
137
// asserting we should use a giant nested ternary.
138
138
private static string [ ] GetIdentifiers ( string symbolName , SymbolType symbolType , CommandHelpers . AliasMap aliases )
139
139
{
140
- if ( symbolType is not SymbolType . Function )
141
- {
142
- return new [ ] { symbolName } ;
143
- }
144
-
145
140
if ( ! aliases . CmdletToAliases . TryGetValue ( symbolName , out List < string > foundAliasList ) )
146
141
{
147
142
return new [ ] { symbolName } ;
@@ -165,22 +160,31 @@ public async Task<IEnumerable<SymbolReference>> ScanForReferencesOfSymbolAsync(
165
160
return Enumerable . Empty < SymbolReference > ( ) ;
166
161
}
167
162
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 ) ;
172
172
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
176
181
{
177
- targetName = aliasDefinition ;
182
+ allIdentifiers = new [ ] { symbol . Id } ;
178
183
}
179
184
180
185
await ScanWorkspacePSFiles ( cancellationToken ) . ConfigureAwait ( false ) ;
181
186
182
187
List < SymbolReference > symbols = new ( ) ;
183
- string [ ] allIdentifiers = GetIdentifiers ( targetName , symbol . Type , aliases ) ;
184
188
185
189
foreach ( ScriptFile file in _workspaceService . GetOpenedFiles ( ) )
186
190
{
0 commit comments