Skip to content

Commit

Permalink
fix(complete): Don't complete files for any value
Browse files Browse the repository at this point in the history
We now need to opt-in to path completions for values, which can be as
simple as setting the value parser to be for `PathBuf`s.

We'll now show a lot less irrelevant completions.
  • Loading branch information
epage committed Oct 8, 2024
1 parent 2e309bd commit 244578e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ cargo-util = { version = "0.2.14", path = "crates/cargo-util" }
cargo-util-schemas = { version = "0.7.0", path = "crates/cargo-util-schemas" }
cargo_metadata = "0.18.1"
clap = "4.5.18"
clap_complete = { version = "4.5.29", features = ["unstable-dynamic"] }
clap_complete = { version = "4.5.32", features = ["unstable-dynamic"] }
color-print = "0.3.6"
core-foundation = { version = "0.10.0", features = ["mac_os_10_7_support"] }
crates-io = { version = "0.40.4", path = "crates/crates-io" }
Expand Down
7 changes: 5 additions & 2 deletions src/bin/cargo/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,11 @@ fn main() {
let _span = tracing::span!(tracing::Level::TRACE, "completions").entered();
let args = std::env::args_os();
let current_dir = std::env::current_dir().ok();
let completer =
clap_complete::CompleteEnv::with_factory(|| cli::cli(&mut gctx)).var("CARGO_COMPLETE");
let completer = clap_complete::CompleteEnv::with_factory(|| {
let mut gctx = GlobalContext::default().expect("already loaded without errors");
cli::cli(&mut gctx)
})
.var("CARGO_COMPLETE");
if completer
.try_complete(args, current_dir.as_deref())
.unwrap_or_else(|e| {
Expand Down

0 comments on commit 244578e

Please sign in to comment.