Skip to content

Commit ef241af

Browse files
committed
Auto merge of #14592 - epage:trace-completions, r=weihanglo
perf: Improve quality of completion performance traces ### What does this PR try to resolve? - `CompleteEnv::complete` calls `std::process::exit`, causing the traces not to be flushed - Its hard to see where overhead is coming from for completions without tracing it This was inspired by #14552 ### How should we test and review this PR? ### Additional information
2 parents 8fc3ff4 + 77e09b1 commit ef241af

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/bin/cargo/main.rs

+14-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,20 @@ fn main() {
3131

3232
let nightly_features_allowed = matches!(&*features::channel(), "nightly" | "dev");
3333
if nightly_features_allowed {
34-
clap_complete::CompleteEnv::with_factory(|| cli::cli(&mut gctx))
35-
.var("CARGO_COMPLETE")
36-
.complete();
34+
let _span = tracing::span!(tracing::Level::TRACE, "completions").entered();
35+
let args = std::env::args_os();
36+
let current_dir = std::env::current_dir().ok();
37+
let completer =
38+
clap_complete::CompleteEnv::with_factory(|| cli::cli(&mut gctx)).var("CARGO_COMPLETE");
39+
if completer
40+
.try_complete(args, current_dir.as_deref())
41+
.unwrap_or_else(|e| {
42+
let mut shell = Shell::new();
43+
cargo::exit_with_error(e.into(), &mut shell)
44+
})
45+
{
46+
return;
47+
}
3748
}
3849

3950
let result = if let Some(lock_addr) = cargo::ops::fix_get_proxy_lock_addr() {

0 commit comments

Comments
 (0)