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
Allow factory suggestions to have parser context #2613
Conversation
@@ -123,7 +123,21 @@ public E parseFromInput(String input, ParserContext context) throws InputParseEx | |||
* @param index the index of the argument to get suggestions for. | |||
* @return a stream of suggestions matching the given input for the argument at the given index. | |||
*/ | |||
protected abstract Stream<String> getSuggestions(String argumentInput, int index); | |||
protected Stream<String> getSuggestions(String argumentInput, int index) { | |||
return Stream.empty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should default to the new method with an empty parser context
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should default to the new method with an empty parser context
I've swapped them round 5c257f6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant that they should both default to each other so parsers can implement one of either method and it will still work. Similar is already done in extents https://github.com/IntellectualSites/FastAsyncWorldEdit/blob/main/worldedit-core/src/main/java/com/sk89q/worldedit/extent/InputExtent.java#L52-L59
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a dumb question, but would there be any risk if someone did not overwrite one or both of them when using the API? Would the getSuggestions not just loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I suppose we're not necessarily going to always do suggestions? Return it to how it was but add a deprecation to it I think, as that method should never be called; overriding is fine but calling is not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the Deprecated tag & a note: 2873359
Much appreciated! |
Overview
Closely mirrors upstream changes in EngineHub/WorldEdit#2236
"This is a refactor to allow access to a ParserContext within the suggestion methods. This is required for any suggestions within the factory parser that are player-specific"
Description
This PR adds context as an option to the getSuggestions() method of parsers.
While no changes to existing Masks or Patterns are present, this change would allow for that to be done in future.
Originally I had gone through and added context to every parser in FAWE, allowing for the new
getSuggestions(String argumentInput, int index, ParserContext context)
method in RichParser to be abstract, replacing the existing method without context.However, that would be a breaking change for any addon plugin using rich parsing such as Arceon.
While it does work & prevents breaking existing parsers, I don't think my approach of 2x methods looks the best so I would appreciate any thoughts on that.
I have tested against existing FAWE, Arceon, and my own custom masks/patterns to double check this is backwards compatible.
It's worth mentioning that my reason for pursuing this change is a custom mask I implemented which would benefit from player-specific tab completion.
Additionally as a basic example, this is a mask that wants a Y value, which can suggest the user's Y level:
Submitter Checklist
@since TODO
.