diff --git a/tools/rust_analyzer/aquery.rs b/tools/rust_analyzer/aquery.rs index 83f8ac2922..6fc9c2ff3c 100644 --- a/tools/rust_analyzer/aquery.rs +++ b/tools/rust_analyzer/aquery.rs @@ -94,7 +94,22 @@ pub fn get_crate_specs( ) -> anyhow::Result> { log::info!("running bazel aquery..."); log::debug!("Get crate specs with targets: {:?}", targets); - let target_pattern = format!("deps({})", targets.join("+")); + let target_pattern = format!( + "deps({})", + targets + .iter() + .map(|t| { + if let Some(stripped) = t.strip_prefix('-') { + format!(" - {stripped}") + } else { + format!(" + {t}") + } + }) + .collect::>() + .join("") + .trim_start_matches(" + ") + .to_owned() + ); let mut aquery_command = bazel_command(bazel, Some(workspace), Some(output_base)); aquery_command diff --git a/tools/rust_analyzer/lib.rs b/tools/rust_analyzer/lib.rs index 4ea641e6a0..dcc5ecf0f4 100644 --- a/tools/rust_analyzer/lib.rs +++ b/tools/rust_analyzer/lib.rs @@ -112,6 +112,7 @@ fn generate_crate_info( "--aspects={rules_rust}//rust:defs.bzl%rust_analyzer_aspect" )) .arg("--output_groups=rust_analyzer_crate_spec,rust_generated_srcs,rust_analyzer_proc_macro_dylib,rust_analyzer_src") + .arg("--") .args(targets) .output()?;