rust-lang / rust-analyzer

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

Why load all folders in workspace #11588

Open tjx666 opened 2 years ago

tjx666 commented 2 years ago

In following workspace, there are may folders. Each folder is a crate. When I open this workspace, rust-analyzer will load all folders which heavily increae the timeout to get seamatic highlight and intellisence.

image

Why not just load the folder which user had open rust file in it?

For example, when I open the main.rs in folder enums, just load the metadata of this crate.

My workspace settings:

image
bjorn3 commented 2 years ago

You can set "rust-analyzer.cache.warmup": false to disable warming up of cache at startup.

tjx666 commented 2 years ago

@bjorn3 I tried it, but useless.

image

bjorn3 commented 2 years ago

That is running the build scripts of all crates to get generated source files and compiling all proc macros. The results of this are cached by cargo, so you should only have to pay for it once if you don't change any build scripts or proc macros even if you restart rust-analyzer. If you want to disable this you can use set rust-analyzer.cargo.runBuildScripts and rust-analyzer.procMacro.enable to false. This may break things if dependencies of you depend on them though.

https://github.com/rust-analyzer/rust-analyzer/blob/cbbb7f351f1b6297f0da91ea12d323051e71380c/crates/project_model/src/build_scripts.rs#L153

tjx666 commented 2 years ago

When I restart rust-analyzer, it will still load all crates again even if I didn't change anything. All the crates in my workspace doesn't depend each other. Why not rust-analyze analyzes the dependency relationship and load only the open folder and it's dependecies.

calops commented 1 year ago

I do wish there was an option to disable indexing everything whenever I open a crate within a workspace. Right now, the only workaround I've found is to temporarily comment the workspace line in the crate's Cargo.toml, otherwise indexing time and memory usage are simply unbearable. But it's tedious to do it every time I switch projects.

lnicola commented 1 year ago

@calops have you tried disabling rust-analyzer.cachePriming.enable?

calops commented 1 year ago

It is better with that setting (thanks for that), however it still builds all the proc macros of the other crates, and still cargo check everything by default (although I can override that command, I feel like there should be a less hacky solution for this).

It also seems to not index the dependencies of my crate when I do this? If that's right, it's still not a suitable solution for me.

zjp-CN commented 6 months ago

It is better with that setting (thanks for that), however it still builds all the proc macros of the other crates, and still cargo check everything by default (although I can override that command, I feel like there should be a less hacky solution for this).

IIUC Your requirement seems not related to the issue. You want cargo-check without --workspace, then just set check.workspace to false since https://github.com/rust-lang/rust-analyzer/pull/16510 .

calops commented 6 months ago

Yeah that's fair, this new option solves my use-case.