Skip to content

If Argument.HelpName was set, HelpBuilder.Default calls GetCompletions but ignores the result #2038

@KalleOlaviNiemitalo

Description

@KalleOlaviNiemitalo

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.

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.

Metadata

Metadata

Assignees

Labels

Area-CompletionsRelated to support for tab completionArea-HelpbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions