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

fix invalid suggestions when parsing of argument fails #401

Merged
merged 3 commits into from
Nov 28, 2022

Conversation

derklaro
Copy link
Contributor

@derklaro derklaro commented Nov 1, 2022

The current suggestion provider for dynamic arguments adds the suggestions of a failed parsed argument as well when stepping over it. This can for example be triggered when an integer argument is required, but a wrong value is provided. Consider the following case: some_command <number <enum>. When the user inputs something like some_command world and tries to tab complete, the suggestions for the number argument show up. This is caused by a failed parse of the number argument, which doesn't step out of the current suggestion process for the argument, but rather continues to add all suggestions for it.

To fix this behaviour, we need to break the completion process if either the preprocessor or the parser isn't accepting the input and more arguments are provided.

@@ -390,7 +404,7 @@ void testLiteralWithVariable() {
Assertions.assertEquals(Arrays.asList("vici", "vidi"), suggestions3);
final String input4 = "literal_with_variable vidi";
final List<String> suggestions4 = manager.suggest(new TestCommandSender(), input4);
Assertions.assertEquals(Collections.emptyList(), suggestions4);
Assertions.assertEquals(Collections.singletonList("vidi"), suggestions4);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test was disabled & wrong previously. Without my change the test wouldn't pass as well as "vidi" would be given as a suggestion.

@derklaro
Copy link
Contributor Author

derklaro commented Nov 2, 2022

One thing I just tough of is that with this change the suggestion processor now pretty much relies on the fact that people are using the api correctly. While there shouldn't be any changes made to the command input queue during the (pre-) process, the whole check & further argument tries will fail if users are changing the queue.

I will change that later, so that the queue gets reset in case of a (pre-) processing failure.

@derklaro
Copy link
Contributor Author

derklaro commented Nov 2, 2022

Should be fine now

@derklaro
Copy link
Contributor Author

derklaro commented Nov 2, 2022

Valid argument:
image

Invalid argument:
image

@jpenilla jpenilla merged commit 00a58b5 into Incendo:1.8.0-dev Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants