Skip to content

Completions can be called from Help and it's hard to make the distinction #1584

Open

Description

@guillaume86

Currently if I don't want to show completions in the help text, I have to ressort to this method to detect if that was the help that called my completions (and that only works because I use subcommands):

private static bool IsHelpCall(CompletionContext context)
{
    return context.ParseResult.CommandResult?.Command is RootCommand;
}

I'd like to have an API for this, maybe adding an enum "InvocationContext(Suggest|ShowHelp)" to the CompletionContext?

It's not crucial to the issue but here are a few reasons I want to show different results:

  • completions can be slow to return
  • there can be a lot of results, especially if WordToComplete is empty
  • I just don't want to show them in the help text

Activity

  1. added
    bug
    Area-Completions
    on Jan 28, 2022
  2. jonsequitur commented on Jan 28, 2022

    @jonsequitur
    Contributor

    Have you looked at the HelpBuilder.CustomizeSymbol APIs? I think these can be used to replace the default completions behavior but I'm not certain of it. If they can't be used this way then we should fix that. I'll give it a try as well and report back.

  3. KalleOlaviNiemitalo commented on Jun 17, 2022

    @KalleOlaviNiemitalo

    I had some difficulty reproducing this issue because I did not know that the default help displays the completions only for Argument and not for Option.

    var completions = (argument is { } a
    ? a.GetCompletions()
    : Array.Empty<CompletionItem>())
    .Select(item => item.Label)
    .ToArray();

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompletionsArea-Helpbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions