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

feat: add completions for add --path #15288

Merged
merged 1 commit into from
Mar 10, 2025

Conversation

nooma-42
Copy link
Contributor

What does this PR try to resolve?

Related to #14520

This PR introduces auto-completion for the cargo add --path option. When a user types cargo add --path and presses the TAB key, the system will automatically detect directories in the current path and suggestion prioritizes directory containing a Cargo.toml file.

How should we test and review this PR?

To verify this feature, follow these steps:

In the terminal, type cargo add --path
Press the TAB key.
You should see suggestions only for directories in the current path that contain a Cargo.toml file being prioritized, such as ./src/ (if ./src/Cargo.toml exists).

2025-03-10.11.52.37.mov

@rustbot
Copy link
Collaborator

rustbot commented Mar 10, 2025

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-cli Area: Command-line interface, option parsing, etc. Command-add S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 10, 2025
Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look nice! Thanks!

I wonder if we want to de-prioritize hidden directories, but that can leave for future discussion.

@weihanglo weihanglo enabled auto-merge March 10, 2025 04:03
@weihanglo weihanglo added this pull request to the merge queue Mar 10, 2025
Merged via the queue into rust-lang:master with commit 42b6ae8 Mar 10, 2025
21 checks passed
Comment on lines +103 to +107
.conflicts_with("git")
.add(clap_complete::engine::ArgValueCompleter::new(
clap_complete::engine::PathCompleter::any()
.filter(|path| path.join("Cargo.toml").exists()),
)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future changes, should we refactor out these --path completers into https://github.com/rust-lang/cargo/blob/master/src/cargo/util/command_prelude.rs ? We have two already and I believe there is a third and we'll be wanting to add more context to these

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. Command-add S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants