-
Notifications
You must be signed in to change notification settings - Fork 78
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
Apply "Parsing With Derivatives" incremental parsing to Bash tab completion #119
Apply "Parsing With Derivatives" incremental parsing to Bash tab completion #119
Conversation
zio-cli/shared/src/main/scala/zio/cli/completion/RegularLanguage.scala
Outdated
Show resolved
Hide resolved
zio-cli/shared/src/main/scala/zio/cli/completion/RegularLanguage.scala
Outdated
Show resolved
Hide resolved
zio-cli/shared/src/main/scala/zio/cli/completion/PrimTypeCompletion.scala
Outdated
Show resolved
Hide resolved
@harveywi Can you bring this up to date so we can merge? |
Yes - I'll set some time aside this weekend, or early next week if needed. I think there's just a merge conflict that (hopefully) won't be too challenging to resolve. |
@jdegoes I am almost done refreshing this PR - there was considerable code churn and I went on a side quest to upgrade To speed things along, I may see if I can just mimic the one or two methods from |
Thanks for the update! |
fdf488f
to
adbbd4b
Compare
adbbd4b
to
c82b510
Compare
Ok - I think that should do it. 🤷 |
Looks great! Can you resolve conflicts? |
Did I miss some conflicts? I had rebased this PR off of the latest (as of now) |
Sorry must have been a stale browser window. Looks great, and all merged in! 💪 |
Overview
This PR adapts the Parsing With Derivatives (PwD) functional pearl to the problem of CLI tab completion. Currently, this is only supported for Bash tab completion, but it should be possible to use this routine for tab completion with other shells.
PwD for Incremental Parsing
For any
zio.cli.Command
instance, there is a corresponding regular language that contains all of the instance's valid sequences of command line arguments. We first build a data structure that represents this regular language, then use the PwD algorithm to incrementally update this data structure as a kind of incremental parsing.As we process each user-provided command line argument from left to right, the PwD algorithm gives us a "residual language" that represents all of the valid arguments that can be provided to the right of the current argument. So all we have to do is calculate the residual language for everything to the left of the CLI cursor position, then return a list of all of the residual language's first tokens that share a prefix with the token at the cursor position.
Notes on Latency
Since the Bash
complete
machinery will call your binary to calculate tab completions, and satisfactory experience with tab completion requires low latency, we highly recommend building your binary usinggraalvm
native-image --no-fallback
.