-
Notifications
You must be signed in to change notification settings - Fork 413
Description
HelpBuilder.Default.GetArgumentUsageLabel(Argument argument) calls argument.GetCompletions() unless argument.ValueType is bool nor bool?. However, if argument.HelpName is a non-empty string, then GetArgumentUsageLabel ignores the result of GetCompletions. In that situation, it would be better if GetArgumentUsageLabel skipped the GetCompletions call. Doing so would improve performance if the application has slow completion sources.
command-line-api/src/System.CommandLine/Help/HelpBuilder.Default.cs
Lines 66 to 92 in 6524142
| string firstColumn; | |
| var completions = argument | |
| .GetCompletions(CompletionContext.Empty) | |
| .Select(item => item.Label) | |
| .ToArray(); | |
| var arg = argument; | |
| var helpName = arg?.HelpName ?? string.Empty; | |
| if (!string.IsNullOrEmpty(helpName)) | |
| { | |
| firstColumn = helpName!; | |
| } | |
| else if (completions.Length > 0) | |
| { | |
| firstColumn = string.Join("|", completions); | |
| } | |
| else | |
| { | |
| firstColumn = argument.Name; | |
| } | |
| if (!string.IsNullOrWhiteSpace(firstColumn)) | |
| { | |
| return $"<{firstColumn}>"; | |
| } | |
| return firstColumn; |
This scenario was not optimized in #1367 when HelpBuilder was changed to display Argument.HelpName.
Fixing this might solve dotnet/sdk#27374, in which .NET SDK uses a completion callback that ends up resolving MSBuild SDKs from NuGet, even though the completions won't be displayed in help. Such a slow completion callback could still be intolerable in dotnet-suggest, though.