-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Tracking Issue for native-completion #14520
Comments
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.
feat: Add custom completer for `cargo -Z <TAB>` ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo -Z <TAB>`
feat: Add custom completer for completing bin names ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo build --bin=<TAB>`
feat: Add custom completer for completing installed binaries ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo uninstall <TAB>`
feat: Add custom completer for `cargo -Z <TAB>` ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo -Z <TAB>`
feat: Add custom completer for completing target triple ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo build --target=<TAB>`
feat: Add custom completer for completing test names ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo test --test <TAB>`
feat: Add custom completer for completing benchmark names ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo build --bench=<TAB>`
@shannmu in testing this, some of the output isn't ideal. The new completer is respecting the documented behavior in We'll need to identify places to sprinkle |
Fish does a lot of parsing of Cargo output and people doing that is a reason we're careful about changing our output. It would be good to see if we could be feature parity with them and get them to switch to our completion generation. Looking over what they do in addition to things specified
See https://github.com/fish-shell/fish-shell/blob/master/share/completions/cargo.fish |
The file paths fallback does indeed affect the user experience. I was thinking if we could temporarily document this issue in the tracking issue. Once the main logic of the various completers is resolved, we can revisit and determine in which cases we don't need the file paths fallback and in which cases it is necessary. |
feat: Add custom completer for `cargo help <TAB>` ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo help <TAB>` ### Additional information The current completer function is quite slow because it executes too many functions. One idea I have is to use the file!() macro to list the filenames under the commands directory, excluding mod.rs, and return them as the completion results. Would this approach be too hacky?
feat: Add custom completer for `cargo build --example=<TAB>` ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo build --example=<TAB>`
feat: Add custom completer for `cargo help <TAB>` ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo help <TAB>` ### Additional information The current completer function is quite slow because it executes too many functions. One idea I have is to use the file!() macro to list the filenames under the commands directory, excluding mod.rs, and return them as the completion results. Would this approach be too hacky?
feat: Add support for completing `cargo update <TAB>` ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for `cargo update <TAB>`
Is there any difference in the completion of the |
@shannmu Both are defined as coming from config, so they should be the same. |
…page feat: Add custom completer for completing registry name ### What does this PR try to resolve? Tracking issue #14520 Add custom completer for completing `cargo publish --registry <TAB>` and `cargo add --registry <TAB>`.
This would be handled by completing the external subcommand. Support for this in clap was merged in clap-rs/clap#5706. For the first two items, an existing place where cargo collects this information is https://github.com/rust-lang/cargo/blob/master/src/bin/cargo/main.rs#L183-L254 |
…mmands function (#15075) Hey there, I just moved the functionality of the third-party subcommand from the [list_commands](https://github.com/rust-lang/cargo/blob/master/src/bin/cargo/main.rs#L184) function to another new function by the name of third_party_subcommand name and called that function in the list_commands function. From my understanding regarding the third-party subcommand from this [tracking issue](#14520), following points should be performed. - The code that gathers third-party subcommands in list_commands should be moved into a separate function that I did. - This new function will be called both by list_commands and the code for adding subcommand completions. Although I called the function in the list_commands but didn't understand the second point. - Test the change that I made in the first place but it gave me this error: ![carbon (68)](https://github.com/user-attachments/assets/fb4c5a55-ea4b-4d22-b187-c2a417f5128d) <!-- Thanks for submitting a pull request 🎉! Here are some tips for you: * If this is your first contribution, read "Cargo Contribution Guide" first: https://doc.crates.io/contrib/ * Run `cargo fmt --all` to format your code changes. * Small commits and pull requests are always preferable and easy to review. * If your idea is large and needs feedback from the community, read how: https://doc.crates.io/contrib/process/#working-on-large-features * Cargo takes care of compatibility. Read our design principles: https://doc.crates.io/contrib/design.html * When changing help text of cargo commands, follow the steps to generate docs: https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages * If your PR is not finished, set it as "draft" PR or add "WIP" in its title. * It's ok to use the CI resources to test your PR, but please don't abuse them. ### What does this PR try to resolve? Explain the motivation behind this change. A clear overview along with an in-depth explanation are helpful. You can use `Fixes #<issue number>` to associate this PR to an existing issue. ### How should we test and review this PR? Demonstrate how you test this change and guide reviewers through your PR. With a smooth review process, a pull request usually gets reviewed quicker. If you don't know how to write and run your tests, please read the guide: https://doc.crates.io/contrib/tests ### Additional information Other information you want to mention in this PR, such as prior arts, future extensions, an unresolved problem, or a TODO list. -->
Hey there, As mentioned in this [issue](#14520), I worked on the functionality of autocompleting the user-defined aliases and I moved the code of user-defined aliases into a separate function by defining two parameters. The first one is global context or gctx and the second one is the commands that can be called in the list_commands function. Thank you! <!-- Thanks for submitting a pull request 🎉! Here are some tips for you: * If this is your first contribution, read "Cargo Contribution Guide" first: https://doc.crates.io/contrib/ * Run `cargo fmt --all` to format your code changes. * Small commits and pull requests are always preferable and easy to review. * If your idea is large and needs feedback from the community, read how: https://doc.crates.io/contrib/process/#working-on-large-features * Cargo takes care of compatibility. Read our design principles: https://doc.crates.io/contrib/design.html * When changing help text of cargo commands, follow the steps to generate docs: https://github.com/rust-lang/cargo/tree/master/src/doc#building-the-man-pages * If your PR is not finished, set it as "draft" PR or add "WIP" in its title. * It's ok to use the CI resources to test your PR, but please don't abuse them. ### What does this PR try to resolve? Explain the motivation behind this change. A clear overview along with an in-depth explanation are helpful. You can use `Fixes #<issue number>` to associate this PR to an existing issue. ### How should we test and review this PR? Demonstrate how you test this change and guide reviewers through your PR. With a smooth review process, a pull request usually gets reviewed quicker. If you don't know how to write and run your tests, please read the guide: https://doc.crates.io/contrib/tests ### Additional information Other information you want to mention in this PR, such as prior arts, future extensions, an unresolved problem, or a TODO list. -->
Summary
Original issue: #6645
Implementation:
cargo uninstall <TAB>
(feat: Add custom completer for completing installed binaries #14534)cargo build --bin=<TAB>
(feat: Add custom completer for completing bin names #14533)cargo build --bench=<TAB>
(feat: Add custom completer for completing benchmark names #14532)cargo build --example=<TAB>
(feat: Add custom completer forcargo build --example=<TAB>
#14531)cargo test --test=<TAB>
(feat: Add custom completer for completing test names #14548)cargo update <TAB>
(feat: Add support for completingcargo update <TAB>
#14552)cargo build --package=<TAB>
(cli suggestions for--package
#15004, feat: Add custom completer for completingcargo build --packge <TAB>
#14553)cargo help <TAB>
(feat: Add custom completer forcargo help <TAB>
#14557)cargo -Z <TAB>
(feat: Add custom completer forcargo -Z <TAB>
#14536)cargo build --target=<TAB>
(feat: Add custom completer for completing target triple #14535)cargo +<TAB>
to complete toolchain namecargo <TAB>
to complete aliases defined inconfig.toml
cargo <TAB>
to complete third-party subcommand namescargo publish --registry=<TAB>
(feat: Add custom completer for completing registry name #14656)cargo add --registry=<TAB>
(feat: Add custom completer for completing registry name #14656)--features
cargo add <TAB>
andcargo install <TAB>
using crate.io search API+toolchain
argumentDocumentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#native-completions
Testing instructions: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#native-completions
Unresolved Issues
Open Questions
bash
,zsh
fish
,elvish
,powershell
bash
,fish
,zsh
,powershell
,elvish
Future Extensions
cargo <TAB>
to cargo scriptscargo builder --manifest-path<TAB>
cargo test <TAB>
cargo --explain=<TAB>
cargo builder --features=<TAB>
cargo builder --profile=<TAB>
cargo install --path<TAB>
cargo add --path<TAB>
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
The text was updated successfully, but these errors were encountered: