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

Allow factory suggestions to have parser context #2613

Merged
merged 7 commits into from Mar 15, 2024

Conversation

Zeranny
Copy link
Contributor

@Zeranny Zeranny commented Mar 10, 2024

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:

image

Submitter Checklist

Edit tasklist title
Beta Give feedback Tasklist Submitter Checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Make sure you are opening from a topic branch (/feature/fix/docs/ branch (right side)) and not your main branch.
    Options
  2. Ensure that the pull request title represents the desired changelog entry.
    Options
  3. New public fields and methods are annotated with @since TODO.
    Options
  4. I read and followed the contribution guidelines.
    Options

@Zeranny Zeranny marked this pull request as ready for review March 10, 2024 21:18
@Zeranny Zeranny requested a review from a team as a code owner March 10, 2024 21:18
@@ -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();
Copy link
Member

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

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 should default to the new method with an empty parser context

I've swapped them round 5c257f6

Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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

@dordsor21 dordsor21 requested a review from a team March 15, 2024 15:47
@NotMyFault NotMyFault added the Enhancement New feature or request label Mar 15, 2024
@NotMyFault
Copy link
Member

Much appreciated!

@NotMyFault NotMyFault merged commit 37d4e9b into IntellectualSites:main Mar 15, 2024
10 checks passed
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

Successfully merging this pull request may close these issues.

None yet

3 participants