Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4194473

Browse files
Constrain use of ConcurrentDictionary to CommandHelpers
Which is where it might be accessed concurrently as a cache, but we can use `IDictionary` (and return a copy of the caches) to the rest of the users.
1 parent ad17ec4 commit 4194473

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

‎src/PowerShellEditorServices/Services/PowerShell/Utility/CommandHelpers.cs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,16 +177,10 @@ public static async Task<string> GetCommandSynopsisAsync(
177177
/// Gets all aliases found in the runspace
178178
/// </summary>
179179
/// <param name="executionService"></param>
180-
public static async Task<(ConcurrentDictionary<string, List<string>>, ConcurrentDictionary<string, string>)> GetAliasesAsync(IInternalPowerShellExecutionService executionService)
180+
public static async Task<(Dictionary<string, List<string>>, Dictionary<string, string>)> GetAliasesAsync(IInternalPowerShellExecutionService executionService)
181181
{
182182
Validate.IsNotNull(nameof(executionService), executionService);
183183

184-
// TODO: Should we return the caches if they're not empty, or always update?
185-
// if (!s_cmdletToAliasCache.IsEmpty || !s_aliasToCmdletCache.IsEmpty)
186-
// {
187-
// return (s_cmdletToAliasCache, s_aliasToCmdletCache);
188-
// }
189-
190184
IEnumerable<CommandInfo> aliases = await executionService.ExecuteDelegateAsync<IEnumerable<CommandInfo>>(
191185
nameof(GetAliasesAsync),
192186
Execution.ExecutionOptions.Default,
@@ -207,7 +201,8 @@ public static async Task<string> GetCommandSynopsisAsync(
207201
s_aliasToCmdletCache.TryAdd(aliasInfo.Name, aliasInfo.Definition);
208202
}
209203

210-
return (s_cmdletToAliasCache, s_aliasToCmdletCache);
204+
return (new Dictionary<string, List<string>>(s_cmdletToAliasCache),
205+
new Dictionary<string, string>(s_aliasToCmdletCache));
211206
}
212207
}
213208
}

‎src/PowerShellEditorServices/Services/Symbols/SymbolsService.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public async Task<List<SymbolReference>> FindReferencesOfSymbol(
189189
return null;
190190
}
191191

192-
(ConcurrentDictionary<string, List<string>> cmdletToAliases, ConcurrentDictionary<string, string> aliasToCmdlets) = await CommandHelpers.GetAliasesAsync(_executionService).ConfigureAwait(false);
192+
(Dictionary<string, List<string>> cmdletToAliases, Dictionary<string, string> aliasToCmdlets) = await CommandHelpers.GetAliasesAsync(_executionService).ConfigureAwait(false);
193193

194194
// We want to look for references first in referenced files, hence we use ordered dictionary
195195
// TODO: File system case-sensitivity is based on filesystem not OS, but OS is a much cheaper heuristic

‎src/PowerShellEditorServices/Services/Symbols/Vistors/AstOperations.cs‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Collections.Concurrent;
65
using System.Collections.Generic;
76
using System.Diagnostics;
87
using System.Linq;
@@ -160,8 +159,8 @@ public static SymbolReference FindCommandAtPosition(Ast scriptAst, int lineNumbe
160159
public static IEnumerable<SymbolReference> FindReferencesOfSymbol(
161160
Ast scriptAst,
162161
SymbolReference symbolReference,
163-
ConcurrentDictionary<string, List<string>> cmdletToAliasDictionary = default,
164-
ConcurrentDictionary<string, string> aliasToCmdletDictionary = default)
162+
IDictionary<string, List<string>> cmdletToAliasDictionary = default,
163+
IDictionary<string, string> aliasToCmdletDictionary = default)
165164
{
166165
// find the symbol evaluators for the node types we are handling
167166
FindReferencesVisitor referencesVisitor = new(

‎src/PowerShellEditorServices/Services/Symbols/Vistors/FindReferencesVisitor.cs‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33

44
using System;
5-
using System.Collections.Concurrent;
65
using System.Collections.Generic;
76
using System.Management.Automation.Language;
87

@@ -14,8 +13,8 @@ namespace Microsoft.PowerShell.EditorServices.Services.Symbols
1413
internal class FindReferencesVisitor : AstVisitor
1514
{
1615
private readonly SymbolReference _symbolRef;
17-
private readonly ConcurrentDictionary<string, List<string>> _cmdletToAliasDictionary;
18-
private readonly ConcurrentDictionary<string, string> _aliasToCmdletDictionary;
16+
private readonly IDictionary<string, List<string>> _cmdletToAliasDictionary;
17+
private readonly IDictionary<string, string> _aliasToCmdletDictionary;
1918
private readonly string _symbolRefCommandName;
2019
private readonly bool _needsAliases;
2120

@@ -29,8 +28,8 @@ internal class FindReferencesVisitor : AstVisitor
2928
/// <param name="aliasToCmdletDictionary">Dictionary maping aliases to cmdlets for finding alias references</param>
3029
public FindReferencesVisitor(
3130
SymbolReference symbolReference,
32-
ConcurrentDictionary<string, List<string>> cmdletToAliasDictionary = default,
33-
ConcurrentDictionary<string, string> aliasToCmdletDictionary = default)
31+
IDictionary<string, List<string>> cmdletToAliasDictionary = default,
32+
IDictionary<string, string> aliasToCmdletDictionary = default)
3433
{
3534
_symbolRef = symbolReference;
3635
FoundReferences = new List<SymbolReference>();

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /