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 · 5 comments
Open
13 of 24 tasks

Tracking Issue for native-completion #14520

shannmu opened this issue Sep 9, 2024 · 5 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.

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

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>`.
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.
Projects
Status: No status
Development

No branches or pull requests

2 participants