(String) argument suggestions do not show up because argument succeeds parsing
See original GitHub issueI didn’t know whether to put this in the PR or as a separate issue, so I’m putting it out here.
Note: no brigadier is used
In the CommandTree suggestions code, the following is done when providing suggestions for non-static arguments:
// START: Preprocessing
final ArgumentParseResult<Boolean> preParseResult = child.getValue().preprocess(
commandContext,
commandQueue
);
if (preParseResult.getFailure().isPresent() || !preParseResult.getParsedValue().orElse(false)) {
final String value = stringOrEmpty(commandQueue.peek());
commandContext.setCurrentArgument(child.getValue());
return child.getValue().getSuggestionsProvider().apply(commandContext, value);
}
// END: Preprocessing
// START: Parsing
commandContext.setCurrentArgument(child.getValue());
final ArgumentParseResult<?> result = child.getValue().getParser().parse(commandContext, commandQueue);
if (result.getParsedValue().isPresent()) {
commandContext.store(child.getValue().getName(), result.getParsedValue().get());
return this.getSuggestions(commandContext, commandQueue, child);
} else if (result.getFailure().isPresent()) {
final String value = stringOrEmpty(commandQueue.peek());
commandContext.setCurrentArgument(child.getValue());
return child.getValue().getSuggestionsProvider().apply(commandContext, value);
}
It is difficult to see the problem, until you start using suggestion providers. The problem is that when you add a StringArgument with a custom suggestion provider, the parsing will succeed even when the value being parsed isn’t one of the suggestions. As a result, players can start typing and see the full list, but the moment they type one more character, all suggestions disappear.
I will probably fix this in my PR https://github.com/Incendo/cloud/pull/142 but need to know whether this was intentional behavior.
My proposed fix will be to not call the deeper getSuggestions() function when the number of remaining elements in the command queue is 0, and instead do the (parse) failure case.
The only workaround right now is to not use the suggestion provider, but make a custom argument parser which rejects values that aren’t part of the enumeration. That’s not a solution for people that want to accept non-suggested input.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)

Top Related StackOverflow Question
Just rebase onto your other branch; when we merge it, either you rebase this, or we will do it for you if/when this is merged.
Is there a way to make one PR a prerequisite for another PR? I’ll put it in it’s own PR, but need to refer to it from https://github.com/Incendo/cloud/pull/142 otherwise the commit will show up twice, which is weird.