Skip to content

Commit 1eac263

Browse files
authored
Lock around access to s_dynamicSymbols (#52887)
1 parent bb7d629 commit 1eac263

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

src/System.CommandLine.StaticCompletions/DynamicSymbolExtensions.cs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ namespace System.CommandLine.StaticCompletions;
66
/// </summary>
77
public static class DynamicSymbolExtensions
88
{
9+
private static readonly Lock s_guard = new();
10+
911
/// <summary>
1012
/// The state that is used to track which symbols are dynamic.
1113
/// </summary>
@@ -18,38 +20,44 @@ public static class DynamicSymbolExtensions
1820
/// </summary>
1921
public bool IsDynamic
2022
{
21-
get => s_dynamicSymbols.GetValueOrDefault(option, false);
22-
set => s_dynamicSymbols[option] = value;
23-
}
24-
25-
/// <summary>
26-
/// Mark this option as requiring dynamic completions.
27-
/// </summary>
28-
/// <returns></returns>
29-
public Option RequiresDynamicCompletion()
30-
{
31-
option.IsDynamic = true;
32-
return option;
23+
get
24+
{
25+
lock (s_guard)
26+
{
27+
return s_dynamicSymbols.GetValueOrDefault(option, false);
28+
}
29+
}
30+
set
31+
{
32+
lock (s_guard)
33+
{
34+
s_dynamicSymbols[option] = value;
35+
}
36+
}
3337
}
3438
}
3539

3640
extension(Argument argument)
3741
{
38-
/// Indicates whether this argument requires a dynamic call into the dotnet process to compute completions.
39-
public bool IsDynamic
40-
{
41-
get => s_dynamicSymbols.GetValueOrDefault(argument, false);
42-
set => s_dynamicSymbols[argument] = value;
43-
}
44-
4542
/// <summary>
46-
/// Mark this argument as requiring dynamic completions.
43+
/// Indicates whether this argument requires a dynamic call into the dotnet process to compute completions.
4744
/// </summary>
48-
/// <returns></returns>
49-
public Argument RequiresDynamicCompletion()
45+
public bool IsDynamic
5046
{
51-
argument.IsDynamic = true;
52-
return argument;
47+
get
48+
{
49+
lock (s_guard)
50+
{
51+
return s_dynamicSymbols.GetValueOrDefault(argument, false);
52+
}
53+
}
54+
set
55+
{
56+
lock (s_guard)
57+
{
58+
s_dynamicSymbols[argument] = value;
59+
}
60+
}
5361
}
5462
}
5563
}

0 commit comments

Comments
 (0)