From 7f94b33b847b9c0e8ca39fa1ca0719317e3b3ae6 Mon Sep 17 00:00:00 2001 From: utnim2 Date: Sun, 23 Feb 2025 16:13:23 +0530 Subject: [PATCH] feat: add completions for `--manifest-path` --- src/cargo/util/command_prelude.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cargo/util/command_prelude.rs b/src/cargo/util/command_prelude.rs index e11a902a6..bc1d1a6ef 100644 --- a/src/cargo/util/command_prelude.rs +++ b/src/cargo/util/command_prelude.rs @@ -10,6 +10,7 @@ use crate::util::important_paths::find_root_manifest_for_wd; use crate::util::interning::InternedString; use crate::util::is_rustup; use crate::util::restricted_names; +use crate::util::toml::is_embedded; use crate::util::{ print_available_benches, print_available_binaries, print_available_examples, print_available_packages, print_available_tests, @@ -325,7 +326,21 @@ pub trait CommandExt: Sized { self._arg( opt("manifest-path", "Path to Cargo.toml") .value_name("PATH") - .help_heading(heading::MANIFEST_OPTIONS), + .help_heading(heading::MANIFEST_OPTIONS) + .add(clap_complete::engine::ArgValueCompleter::new( + clap_complete::engine::PathCompleter::any().filter(|path: &Path| { + if path.file_name() == Some(OsStr::new("Cargo.toml")) { + return true; + } + if is_embedded(path) { + return true; + } + if path.is_file() && path.extension().is_none() { + return true; + } + false + }), + )), ) }