Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 32 additions & 24 deletions src/System.CommandLine.StaticCompletions/DynamicSymbolExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace System.CommandLine.StaticCompletions;
/// </summary>
public static class DynamicSymbolExtensions
{
private static readonly Lock s_guard = new();

/// <summary>
/// The state that is used to track which symbols are dynamic.
/// </summary>
Expand All @@ -18,38 +20,44 @@ public static class DynamicSymbolExtensions
/// </summary>
public bool IsDynamic
{
get => s_dynamicSymbols.GetValueOrDefault(option, false);
set => s_dynamicSymbols[option] = value;
}

/// <summary>
/// Mark this option as requiring dynamic completions.
/// </summary>
/// <returns></returns>
public Option RequiresDynamicCompletion()
{
option.IsDynamic = true;
return option;
get
{
lock (s_guard)
{
return s_dynamicSymbols.GetValueOrDefault(option, false);
}
}
set
{
lock (s_guard)
{
s_dynamicSymbols[option] = value;
}
}
}
}

extension(Argument argument)
{
/// Indicates whether this argument requires a dynamic call into the dotnet process to compute completions.
public bool IsDynamic
{
get => s_dynamicSymbols.GetValueOrDefault(argument, false);
set => s_dynamicSymbols[argument] = value;
}

/// <summary>
/// Mark this argument as requiring dynamic completions.
/// Indicates whether this argument requires a dynamic call into the dotnet process to compute completions.
/// </summary>
/// <returns></returns>
public Argument RequiresDynamicCompletion()
public bool IsDynamic
{
argument.IsDynamic = true;
return argument;
get
{
lock (s_guard)
{
return s_dynamicSymbols.GetValueOrDefault(argument, false);
}
}
set
{
lock (s_guard)
{
s_dynamicSymbols[argument] = value;
}
}
}
}
}
Loading