Description
Maintainer's notes:
Remaining work for feature parity
- Communicate with bash (feat(complete): Skeleton for Rust-driven completions #3656)
- Complete path
ValueHint
s (feat(complete): Skeleton for Rust-driven completions #3656) - Complete possible values (feat(complete): Skeleton for Rust-driven completions #3656)
- Complete short flags (feat(complete): Skeleton for Rust-driven completions #3656)
- Complete long flags (feat(complete): Skeleton for Rust-driven completions #3656)
- Complete subcommands (feat(complete): Skeleton for Rust-driven completions #3656)
- Communicate with zsh (zsh support for native completions #3916)
- Communicate with fish (fish support for native completions #3917)
- Communicate with Powershell (powershell support for native completions #3918)
- Communicate with Elvish (elvish support for native completions #3919)
- Flag values (Support flags with values in native completions #3920)
- Multiple values (Support multiple values in native completions #3921)
- Hidden (Support hiding flags/subcommands/possible values/aliases for native compeletions #3951)
- Handling of space (Intentionally control when a space is appended for native completions #5587)
- Fix handling of
OsString
to preserve non-UTF8 paths - Document that
stdout
should not be used before getting to completion processing in case the completions are requested (docs(complete): Expand dynamic docs #5643) - FIGNORE support?
- Fulfill Document how to source completions #2488 for these new completions. Ideally, we have the registration script sourced on-demand in the docs so that it is "auto-updating" with the users tool
- Switch native completions to encourage env var initialization #3930
- Verify each shell's behavior with quoting to see if we need to add quoting to what we output
-
clap_complete::env::Elvish
generates code deprecated in 0.18, removed in 0.21 #5729 - Bash outputs everything as one completion, rather than a list of completions #5730
- Lazy loading of dynamic completions #5668
Non-blocking work
- Smarter selection of what to show (Filter and order completions based on input and importance for native completions #5058)
- Delimited values (Support delimited values for native completions #3922)
is_require_equal_set
support (Supportis_require_equal_set
in native completions #3923)last
supporttrailing_var_arg
support- Support subcommand flags in native completion engine #5284 (doesn't appear supported by static completions)
- Removing options based on conflicts (self and others)
- Any App or Arg setting not currently handled by the static completions
- Priority to value delimiter and requires equals
- Complete more
ValueHint
s - Figure out where this will live as the dependency requires are dramatically different than the static completions and this shouldn't be behind a feature flag for forever
- Custom help messages (Allow using a completion-specific candidate description over the candidate's help message in rust-native completions #5063)
- Completing multiple path elements at once (Complete multiple path elements at once #5279)
- nushell support (Dynamic completion for Nushell #5840)
Design considerations
- Make it easy to use for the natively supported shells but allow other shells to be supported
Prior art
- https://github.com/pacak/bpaf
- https://pypi.org/project/argcomplete
- https://github.com/rsteube/carapace
- https://github.com/microsoft/inshellisense
- https://github.com/sigoden/argc-completions
- https://click.palletsprojects.com/en/8.1.x/shell-completion/
#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:
- clap_generate fish: ArgEnum completions not working on toplevel command #2729
- Allow completion of partial commands [Powershell] #2750
- clap_generate PowerShell script does not complete case sensitive options like -S. Only completes -s #2145
- zsh: optional flag with takes_value breaks completions #1822
- Allow the completed command to be an alias #1764
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.