Skip to content

Add discoverConfig Support for rust-analyzer#4075

Open
UebelAndre wants to merge 1 commit into
bazelbuild:mainfrom
UebelAndre:rust-analyzer
Open

Add discoverConfig Support for rust-analyzer#4075
UebelAndre wants to merge 1 commit into
bazelbuild:mainfrom
UebelAndre:rust-analyzer

Conversation

@UebelAndre

@UebelAndre UebelAndre commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

This change improves rust-analyzer support by moving away from rust-project.json and promoting a more automated approach. Documentation has been updated to reflect the recommended integration.

Changes:

  • Implement Build-Event-Service parsing to avoid globbing for bazel outputs.
  • Implements new setup tool that users can invoke to configure their IDE for Bazel-backed rust-analyzer support.

closes #2488
closes #3762

@UebelAndre UebelAndre force-pushed the rust-analyzer branch 7 times, most recently from cc07124 to 6b5e5e9 Compare June 10, 2026 18:39
@UebelAndre UebelAndre marked this pull request as ready for review June 10, 2026 18:58

@illicitonion illicitonion left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still reviewing, but leaving a few comments in case you want to start considering them

Comment thread docs/src/rust_analyzer.md
don't thrash the user's primary `bazel build` analysis cache. The two
Bazel servers — yours and the flycheck one — are fully isolated.

Failed actions are deliberately supported: rustc still emits its

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But presumably anything that depends on the failed action won't attempt to build? Does that impact anything worth noting? Or even worth doing a query/cquery/aquery for if any actions failed?

Comment thread docs/src/rust_analyzer.md
`rust-analyzer` will switch workspaces whenever an out-of-tree file gets opened, essentially indexing that
crate and its dependencies separately. A caveat of this is that _dependents_ of the crate currently being
worked on are not indexed and won't be tracked by `rust-analyzer`.
To force whole-workspace mode instead, drop the `{arg}` from the

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this as a default, it feels useful in a large monorepo, but probably quite annoying in a smaller repo? Do we want to make this a flag (maybe even a required flag, for discoverability) to setup?

# labels against BEP labels to find each action's stderr for
# diagnostics. Without the leading `//`, the match silently
# fails and the wrapper emits no diagnostics for the crate.
"label": "//" + ctx.label.package + ":" + ctx.label.name,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue here with deps from foreign workspaces?

.map(Utf8PathBuf::from)
})
.unwrap_or_else(|| workspace.join(".vscode/.rules_rust_analyzer/output_user_root"));
let _ = std::fs::create_dir_all(&output_user_root);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panic on failure instead of ignoring?

Comment on lines +175 to +187
let _ = serde_json::to_writer(&mut out, &value);
let _ = out.write_all(b"\n");
}
Err(_) => {
// Not strict JSON — pass through unmodified so we don't
// silently drop a diagnostic format we don't recognize.
let _ = out.write_all(line.as_bytes());
let _ = out.write_all(b"\n");
}
}
}
}
let _ = out.flush();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Panics rather than swallow on failures?


/// See `rust_analyzer.rs` for the rationale; mirrors the same fallback so
/// editors that spawn the wrapper directly don't trip RunfilesDirNotFound.
fn ensure_runfiles_env() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth extracting into a lib? Or even our runfiles lib as an optional unofficial thing?

/// function returning the findings; callers are responsible for surfacing
/// them (`log::warn!`, persistent log file, etc).
pub fn diagnose(crate_specs: &BTreeSet<CrateSpec>) -> AssemblyDiagnostics {
use std::collections::BTreeSet as Set;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the alias?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hermetic vs system rust-analyzer. Infinite cycle in rust-analyzer caused by test deps

2 participants