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

Tracking Issue for native-completion #14520

Open
13 of 24 tasks
shannmu opened this issue Sep 9, 2024 · 6 comments
Open
13 of 24 tasks

Tracking Issue for native-completion #14520

shannmu opened this issue Sep 9, 2024 · 6 comments
Labels
A-cli Area: Command-line interface, option parsing, etc. A-completions Area: shell completions C-tracking-issue Category: A tracking issue for something unstable. call-for-testing Marks issues that require broader testing from the community, e.g. before stabilization.

Comments

@shannmu
Copy link
Contributor

shannmu commented Sep 9, 2024

Summary

Original issue: #6645
Implementation:

Documentation: 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

  • Some tests are disabled on macOS.
  • Distinguish whether different subcommands require path fallback.
  • Completion candidates generation test code per completer.

Open Questions

  • What should we support?
    • Today, cargo supports bash, zsh
    • Currently, this adds fish, elvish, powershell
    • rustup supports bash, fish, zsh, powershell, elvish
    • Are all of sufficient quality? powershell being the biggest question

Future Extensions

  • Add custom completer for cargo <TAB> to cargo scripts
  • Add custom completer for cargo builder --manifest-path<TAB>
  • Add custom completer for cargo test <TAB>
  • Add custom completer for cargo --explain=<TAB>
  • Add custom completer for cargo builder --features=<TAB>
  • Add custom completer for cargo builder --profile=<TAB>
  • Add custom completer for cargo install --path<TAB>
  • Add custom completer for 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.

@shannmu shannmu added the C-tracking-issue Category: A tracking issue for something unstable. label Sep 9, 2024
@epage epage added A-completions Area: shell completions A-cli Area: Command-line interface, option parsing, etc. labels Sep 9, 2024
bors added a commit that referenced this issue Sep 10, 2024
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.
bors added a commit that referenced this issue Sep 11, 2024
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>`
bors added a commit that referenced this issue Sep 16, 2024
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>`
bors added a commit that referenced this issue Sep 16, 2024
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>`
bors added a commit that referenced this issue Sep 16, 2024
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>`
bors added a commit that referenced this issue Sep 17, 2024
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>`
bors added a commit that referenced this issue Sep 17, 2024
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>`
bors added a commit that referenced this issue Sep 17, 2024
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>`
@epage
Copy link
Contributor

epage commented Sep 18, 2024

@shannmu in testing this, some of the output isn't ideal. The new completer is respecting the documented behavior in ValueHint::Unknown which means there are cases like cargo add [TAB] that show file paths when we shouldn't. On the other hand, this is a good default for cargo install --path [TAB].

We'll need to identify places to sprinkle ValueHint::Other

@epage
Copy link
Contributor

epage commented Sep 18, 2024

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

  • They complete --features
  • cargo add and cargo install complete using the crates.io search API
    • This is questionable because that can disclose confidential information

See https://github.com/fish-shell/fish-shell/blob/master/share/completions/cargo.fish

@shannmu
Copy link
Contributor Author

shannmu commented Sep 18, 2024

We'll need to identify places to sprinkle ValueHint::Other

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.

bors added a commit that referenced this issue Sep 18, 2024
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?
bors added a commit that referenced this issue Sep 18, 2024
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>`
bors added a commit that referenced this issue Sep 18, 2024
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?
bors added a commit that referenced this issue Sep 24, 2024
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>`
@shannmu
Copy link
Contributor Author

shannmu commented Oct 8, 2024

Is there any difference in the completion of the --registry option between cargo publish and cargo add?

@epage
Copy link
Contributor

epage commented Oct 8, 2024

@shannmu cargo add corresponds to https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-other-registries while cargo publish --registry is https://doc.rust-lang.org/cargo/commands/cargo-publish.html#publish-options

Both are defined as coming from config, so they should be the same.

bors added a commit that referenced this issue Oct 8, 2024
…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>`.
@epage epage added the call-for-testing Marks issues that require broader testing from the community, e.g. before stabilization. label Dec 13, 2024
@epage
Copy link
Contributor

epage commented Jan 8, 2025

Add custom completer for cargo to complete third-party subcommand names
Add custom completer for cargo to complete aliases defined in config.toml
Add custom completer for cargo + to complete toolchain name

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

github-merge-queue bot pushed a commit that referenced this issue Jan 16, 2025
…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.
-->
github-merge-queue bot pushed a commit that referenced this issue Jan 17, 2025
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.
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli Area: Command-line interface, option parsing, etc. A-completions Area: shell completions C-tracking-issue Category: A tracking issue for something unstable. call-for-testing Marks issues that require broader testing from the community, e.g. before stabilization.
Projects
Status: No status
Development

No branches or pull requests

2 participants