Skip to content

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

Closed

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.

Activity

  1. added
    bug
    Area-Completions
    on Feb 24, 2023
  2. self-assigned this
    on Feb 28, 2023
  3. jonsequitur commented on Mar 3, 2023

    @jonsequitur
    Contributor

    Under proposal #2071, another approach for turning off completions in help output that would be more explicit might look like this:

    switch (parseResult.Action)
    {
        case HelpAction helpAction:
    
            helpAction.UseCompletionsAsExamples = false;
            await helpAction.RunAsync();
    
            break;
    
        //...
    }

    Thoughts?

  4. KalleOlaviNiemitalo commented on Mar 3, 2023

    @KalleOlaviNiemitalo
    Author

    That looks like it would hide all completions from help, not provide the ability to hide the completions of one argument but keep the others.

  5. jonsequitur commented on Mar 3, 2023

    @jonsequitur
    Contributor

    That's true. Does the existing implementation seem intuitive enough? Would deeper help configuration on the symbol objects themselves be more intuitive?

  6. KalleOlaviNiemitalo commented on Mar 6, 2023

    @KalleOlaviNiemitalo
    Author

    In my opinion, the way this works in 2.0 beta 4 is OK as an API, but:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-CompletionsArea-Helpbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions