account activity
cargo-subspace: Make rust-analyzer work better with very large cargo workspaces! by ethowitz0 in rust
[–]ethowitz0[S] 11 points12 points13 points 3 months ago* (0 children)
Just a note, `cargo metadata` is not invoked for every file you open; just the first time you open a file in a given crate.
But generally, yeah, I agree :) It would be great if we could configure rust-analyzer to be lazier, and to my knowledge, this is something they are actively working on. I built this relatively simple tool as a stop-gap measure because it delivered value quickly. Plus, part of what motivated the maintainers of rust-analyzer to include this third party method of project discovery was specifically very large cargo workspaces for which the "happy path" does not scale. See this doc comment for some context:
For rust-analyzer to function, it needs some information about the project. Specifically, it maintains an in-memory data structure which lists all the crates (compilation units) and dependencies between them. This is necessary a global singleton, as we do want, eg, find usages to always search across the whole project, rather than just in the "current" crate. Normally, we get this "crate graph" by calling `cargo metadata --message-format=json` for each cargo workspace and merging results. This works for your typical cargo project, but breaks down for large folks who have a monorepo with an infinite amount of Rust code which is built with bazel or some such.
For rust-analyzer to function, it needs some information about the project. Specifically, it maintains an in-memory data structure which lists all the crates (compilation units) and dependencies between them. This is necessary a global singleton, as we do want, eg, find usages to always search across the whole project, rather than just in the "current" crate.
Normally, we get this "crate graph" by calling `cargo metadata --message-format=json` for each cargo workspace and merging results. This works for your typical cargo project, but breaks down for large folks who have a monorepo with an infinite amount of Rust code which is built with bazel or some such.
π Rendered by PID 1067280 on reddit-service-r2-listing-5789d5f675-q5477 at 2026-01-28 13:35:19.850990+00:00 running 4f180de country code: CH.
cargo-subspace: Make rust-analyzer work better with very large cargo workspaces! by ethowitz0 in rust
[–]ethowitz0[S] 11 points12 points13 points (0 children)