-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 custom completer for completing cargo build --packge <TAB>
#14553
base: master
Are you sure you want to change the base?
Conversation
r? @weihanglo rustbot has assigned @weihanglo. Use |
r? @epage |
src/cargo/util/command_prelude.rs
Outdated
@@ -1067,6 +1073,24 @@ fn get_targets_from_metadata() -> CargoResult<Vec<Target>> { | |||
Ok(targets) | |||
} | |||
|
|||
fn get_package_candidates() -> Vec<clap_complete::CompletionCandidate> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn get_package_candidates() -> Vec<clap_complete::CompletionCandidate> { | |
fn get_ws_member_candidates() -> Vec<clap_complete::CompletionCandidate> { |
src/cargo/util/command_prelude.rs
Outdated
get_packages_from_metadata() | ||
.unwrap_or_default() | ||
.into_iter() | ||
.map(|pkg| clap_complete::CompletionCandidate::new(pkg.name().as_str())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's include the package descriptions
src/cargo/util/command_prelude.rs
Outdated
.collect::<Vec<_>>() | ||
} | ||
|
||
fn get_packages_from_metadata() -> CargoResult<Vec<Package>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn get_packages_from_metadata() -> CargoResult<Vec<Package>> { | |
fn get_ws_member_packages() -> CargoResult<Vec<Package>> { |
☔ The latest upstream changes (presumably #14535) made this pull request unmergeable. Please resolve the merge conflicts. |
1aaae04
to
869064b
Compare
src/cargo/util/command_prelude.rs
Outdated
.help_heading(heading::PACKAGE_SELECTION) | ||
.add(clap_complete::ArgValueCandidates::new( | ||
get_ws_member_candidates, | ||
)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like cargo uninstall
uses this flag for the same reason as the positional argment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arg_package_spec_no_all(
calls this
cargo tree
uses to refer to any package in the dependency graph
arg_package_spec
calls that but all uses look good
…nds during compile time.
…` / `cargo tree --package <TAB>`
869064b
to
2bac0b6
Compare
.help_heading(heading::PACKAGE_SELECTION), | ||
.help_heading(heading::PACKAGE_SELECTION) | ||
.add(clap_complete::ArgValueCandidates::new(move || { | ||
if ["build", "tree"].contains(&name.as_str()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is subtle and going to be very confusing. I wonder if we should better organize the arguments by what kind of package is being requested
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While implementing the completion, I discovered that parameters with the same name require different values under different subcommands. To minimize disruption to the original code, I added the _name
interface, which allows the subcommand being used to be determined at compile time. Is there a better way to determine what kind of package is being requested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some ideas I thought of
- We could have different
arg_package
functions for different roles - We could accept a completer as an argument
What does this PR try to resolve?
Tracking issue github.com/rust-lang/cargo/issues/14520
Add custom completer for
cargo build --package <TAB>