rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
14.25k stars 1.6k forks source link

rust-analyzer optimization for mono-repo #18060

Open techster10173 opened 1 month ago

techster10173 commented 1 month ago

In one of my projects, we operate off of a mono-repo which has multiple rust packages in it. As a result, rust-analyzer attempts to index the entire mono-repo causing the computer to reach very high levels of resource utilization. Would it be be possible to create a feature in which rust-analyzer, if it detects multiple Cargo.toml in leaves of the mono-repo directory, it only runs for the rust project that is currently opened in the IDE?

Thanks!

techster10173 commented 1 month ago

For reference, the IDE that we use is VSCode

alibektas commented 1 month ago

Setting rust-analyzer.linkedProjects should help.

rust-analyzer.linkedProjects (default: []) Disable project auto-discovery in favor of explicitly specified set of projects. Elements must be paths pointing to Cargo.toml, rust-project.json, .rs files (which will be treated as standalone files) or JSON objects in rust-project.json format.

From our manual

Although, to answer your question completely, rust-analyzer looks for a Cargo.toml and runs cargo metadata on the path where the file is located, if your monorepo has a complicated dependency graph, there is nothing it can do but include all dependencies in its analysis. However, if crates are independent, then opening your editor not at the root of your monorepo, but at the root path of the crate should make your life easier.

flodiebold commented 1 month ago

You can turn off cache priming by setting rust-analyzer.cachePriming.enable to false; this will skip the "indexing" step completely at the cost of making the first few requests take very long. You'll also probably want to turn off rust-analyzer.checkOnSave.