8000 Don't suggest nodes which the source does not have requirements for by willkroboth · Pull Request #157 · Mojang/brigadier · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Don't suggest nodes which the source does not have requirements for #157

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

willkroboth
Copy link

Right now, requirements are not checked when generating suggestions. This means that the following test fails:

// Added to `CommandSuggestionsTest`
@Test
public void getCompletionSuggestions_unmetRequirement() throws Exception {
    subject.register(
        literal("parent")
            .then(
                literal("invalid").requires(o -> false)
            )
            .then(
                literal("valid")
            )
    );

    final ParseResults<Object> parse = subject.parse("parent ", source);
    final Suggestions result = subject.getCompletionSuggestions(parse).join();

    // java.lang.AssertionError: 
    //  Expected: <[Suggestion{range=StringRange{start=7, end=7}, text='valid', tooltip='null'}]>
    //  but: was <[Suggestion{range=Strin
8383
gRange{start=7, end=7}, text='invalid', tooltip='null'}, 
    //  Suggestion{range=StringRange{start=7, end=7}, text='valid', tooltip='null'}]>
    assertThat(result.getList(), equalTo(Lists.newArrayList(new Suggestion(StringRange.at(7), "valid"))));
}

Since the invalid literal was given the requirement o -> false, the source cannot execute that node or any of its children. However, invalid is still given as a suggestion. Since the source is not allowed to use this node, it should not have it suggested, since that confusingly suggests it could work.

This PR fixes this issue by ignoring a node's suggestions if the source does not meet its requirements.

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.

1 participant
0