-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Stablize Rust-Native Completion Engine Tracking Issue #3166
Comments
Bash's expectations Inputs for
Inputs for
Output for
Output for
See
|
argcomplete emulates bash's interface in fish by
and then just registers that function https://github.com/kislyuk/argcomplete/blob/develop/argcomplete/shell_integration.py#L60 |
Value hints are supported on
Tooltips are supported on
We should make sure we don't lose these features as part of this transition, ie we shouldn't drop to the lowest common denominator. |
For Powershell Register-ArgumentCompleter
-CommandName <String[]>
-ScriptBlock <ScriptBlock>
[-Native]
[<CommonParameters>] The block receives
The block provides CompletionResult
So it seems like Powershell can fit within rust-driven completions and provide the full feature set. |
I'm starting small and prototyping for just bash support. Looking at argcomplete, it seems they had to use their own shlex implementation. Hoping we can avoid that. The first step is comex/rust-shlex#12. |
Hi, I'm interested in helping with this this I'm developing a few personal tools using clap that would hugely benefit from dynamic completions. Is there any good issues that nobody is working on you could point me towards? |
@happenslol Thanks! Anything unchecked in the "Remaining work" section is up for grabs; just post here that you are getting started on it. The highest priority is the support for each shell as that will help gauge the feasibility and provide feedback on the API. The rest is flushing out parsing implementation. I should split those out into individual issues to make it easier for people to coordinate on those (and to add bounties) but I probably won't have time for another week or so. |
Alright, had a busy week, so I'm only getting back around to this now. I've looked at the work done in #3656, and it looks like the next steps to add zsh and fish support would be to pull some of the functionality out of I'd look at |
@happenslol Yes, that is correct. I'd like to focus on shell support initially as that is where the most unknowns exist |
Oh if cobra is doing the same type of dynamic completions as argcomplete, that is great! That'll serve as a much better example! |
feat: Add native comlpetion with CompleteEnv under the nightly ### What does this PR try to resolve? Related issue #6645 Tracking issue #14520 This PR is the first step to move cargo shell completions to native completions by using `clap_complete` crate. It makes users could complete cargo subcommand and flags. By using `clap_complete` crate, we could extend the supported shells to Bash, Zsh, Elvish, Fish, and PowerShell. However, at the current stage, the support for PowerShell in `clap_complete` is not fully developed. See clap-rs/clap#3166 to get more context about what features `clap_complete` has supported. ### How to test and review this PR? 1. Build a test environment, including the necessary short completion scripts, and the `complete` function to start an interactive shell with the help of a pty device and obtain completion results. 2. Simply test the completion results of subcommands in bash, zsh, fish, elvish.
doc: add notice about clap-rs/clap#3166
Hello @epage I'd love to get involved with this. Where might be a good place to provide some value here (something on the easier side to start maybe)? |
The areas we need the most help are
|
Hey all, just wanted to drop a link to my own hand-rolled implementation of Rust-native argument completion for https://github.com/microsoft/openvmm/blob/main/support/clap_dyn_complete/src/lib.rs Note that I wrote this code a few years back, before the recent uptick in investments in resolving this issue, and may not reflect the current approach This implementation is not fully-featured by any means, but it does include support for several different shells (zsh, fish, powershell), various I'm quite interested in getting this sort of functionality working in |
Some more quick ones
|
@daniel5151 looking over that, some differences in approach
|
@daniel5151 any integrating of ideas from |
@epage, glad to see you took a look through the code! A few additional thoughts, in response to your analysis.
This was quite important to me, as the key completion I wanted to support was akin to navigating a virtual directory listing (i.e: completing But you're right - I certainly recall wrestling with nuances around quoting and shell arguments. Not sure I ever solved it cleanly.
IIRC, async support was purely a nice-to-have. I'm sure some more judicious use of block_on could've worked just as well (at least, for my use-case).
I believe part of the rationale here was that I wanted to plumb-through some shared context into different completion handlers without needing to use a global static.
Given that I basically wrote this implementation "for fun" at $work, I wasn't super keen getting bogged down in forking / digging through And of course - the only performance consideration I had in mind when writing But yeah, ultimately, I only wrote My goal here was to simply call-out some prior art in this space, and have |
@daniel5151 Thank you for sharing. Regarding the issue of allowing completion in the middle of words and with I’ve tried using bash built-in functions like @epage , I have an important deadline on December 2nd, so during this period, I might only push some of the previous PRs. However, I’ve been following the community’s progress on And thanks for your involvement, @calebbourg . I’ve contributed to the |
Maintainer's notes:
Remaining work for feature parity
ValueHint
s (feat(complete): Skeleton for Rust-driven completions #3656)OsString
to preserve non-UTF8 pathsstdout
should not be used before getting to completion processing in case the completions are requested (docs(complete): Expand dynamic docs #5643)clap_complete::env::Elvish
generates code deprecated in 0.18, removed in 0.21 #5729Non-blocking work
is_require_equal_set
support (Supportis_require_equal_set
in native completions #3923)last
supporttrailing_var_arg
supportValueHint
sDesign considerations
Prior art
#3022 was a tipping point for me in realizing that maybe our current approach to completions doesn't work. We effectively have to implement a mostly-untested parser within each shell. Examples of other problems that seem to stem from this:
If we take the approach of argcomplete where we do the parsing in our core code, rather than in each completion script, this will help us share parsing logic between shell, share some or all parsing logic with clap itself, and make a subset of the logic more testable.
We also need to decide whether to morph the existing parser into supporting this or create a custom parser (since the needs are pretty special). If we do a custom parser, we should probably do #2915 first so we can reuse lexing logic between clap and the completion generation. I've also been considering #2912 which would allow reusing the completion logic with any CLI parser.
The text was updated successfully, but these errors were encountered: