Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude desired subcommands from suggestions #409

Open
owljackob opened this issue Jan 21, 2023 · 1 comment
Open

Exclude desired subcommands from suggestions #409

owljackob opened this issue Jan 21, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@owljackob
Copy link

Description

It all consists of the ability to modify the suggestions of subcommands... like to suggest some of them only instead of every single one that is provided.

Expected code

No response

Extra details

No response

@owljackob owljackob added the enhancement New feature or request label Jan 21, 2023
@willkroboth
Copy link
Collaborator

So yeah, subcommands are converted into LiteralArguments, and when Brigadier finds a literal in the command tree, it drops it directly into the list of suggestions. Looking at the code, this is the method used to get the suggestions for a literal command node:
LiteralCommandNode.java#L70-L77

@Override
public CompletableFuture<Suggestions> listSuggestions(final CommandContext<S> context, final SuggestionsBuilder builder) {
    if (literalLowerCase.startsWith(builder.getRemainingLowerCase())) {
        return builder.suggest(literal).buildFuture();
    } else {
        return Suggestions.empty();
    }
}

The return builder.suggest(literal).buildFuture(); part adds the name of the subcommand (literal) into the list of suggestions. That code always runs, except when the text the user input isn't the start of the literal. Most important for this issue, it isn't possible to stop the literal from showing up whenever we want; there just isn't a check for that.

It may be possible to hide subcommands if they were converted to use something that wasn't a literal argument, but I'm not sure how that would work out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants