Skip to content

Commit a1635e8

Browse files
authored
feat: add completions for --manifest-path (#15225)
### What does this PR try to resolve? Add auto completion for `cargo build --manifest-path <TAB>` Related to #14520 Ways this could be handled: 1. Complete nothing **(current nightly behavior)**: users must manually type every character of the path. 2. Complete all files **(current stable behavior)**: users see every file, more than this PR 3. Complete every file name that is accepted by `--manifest-path` **(this PR)**: this may match files that don't have a manifest inside them, implicit or explicit 4. Complete only `Cargo.toml`: Cargo script users will have to manually type in every of the path Generally, completions should err on the side of being overly broad, rather than less, because otherwise users will have to manually type things out This is still an improvement over the stable behavior because you don't have 1. `foo/C[TAB]`, see `Cargo.toml` and `Cargo.lock` 2. `foo/Ca[TAB]`, get `foo/Cargo.toml` ### How should we test and review this PR? [Screencast from 23-02-25 04:09:17 PM IST.webm](https://github.com/user-attachments/assets/6290801c-85bf-4b44-9dcd-6cc431891897)
2 parents 10175b1 + c3c2ea2 commit a1635e8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/cargo/util/command_prelude.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::util::important_paths::find_root_manifest_for_wd;
1010
use crate::util::interning::InternedString;
1111
use crate::util::is_rustup;
1212
use crate::util::restricted_names;
13+
use crate::util::toml::is_embedded;
1314
use crate::util::{
1415
print_available_benches, print_available_binaries, print_available_examples,
1516
print_available_packages, print_available_tests,
@@ -325,7 +326,18 @@ pub trait CommandExt: Sized {
325326
self._arg(
326327
opt("manifest-path", "Path to Cargo.toml")
327328
.value_name("PATH")
328-
.help_heading(heading::MANIFEST_OPTIONS),
329+
.help_heading(heading::MANIFEST_OPTIONS)
330+
.add(clap_complete::engine::ArgValueCompleter::new(
331+
clap_complete::engine::PathCompleter::any().filter(|path: &Path| {
332+
if path.file_name() == Some(OsStr::new("Cargo.toml")) {
333+
return true;
334+
}
335+
if is_embedded(path) {
336+
return true;
337+
}
338+
false
339+
}),
340+
)),
329341
)
330342
}
331343

0 commit comments

Comments
 (0)