-
Notifications
You must be signed in to change notification settings - Fork 1.7k
rust-analyzer with VSCode Workspaces appears to run redundant checks. #13162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Am I perhaps holding this wrong? Is there some setting that I've missed that should change this behaviour? |
Not sure why rust-analyzer would invoke multiple cargo instances (maybe it just considers every vscode workspace member individually), but if they all operate on the same cargo workspace, it shouldn't slow anything down as all invocations except for the first will simply block until the first is done and then see that nothing needs to be done anymore and just exit. |
This makes sense, but in practice in our monorepo, removing my 2021 workspace roots gives me a substantial drop in ongoing memory usage, and If there's anything useful I can share that would help troubleshoot what's going on there, I'd be very happy to provide it. |
Unfortunately I'm not really familiar with the relevant code. |
No worries, I appreciate your input at any rate. I think we'll move forward by removing rust projects as roots from our VSCode workspace until this is addressed in some way. |
r-a invokes a check per cargo workspace in the opened VSCode workspace. It is rather odd if it invokes all of those with the same manifest path though, this sounds like you have a somewhat "special" set up maybe that confuses r-a, though I can't really say much about that without knowing the project structure of course. I'll take a look at the regex example when I get the time, although I doubt that will run the checks with the same manifest path for the workspaces. |
I was a little surprised too, but I was definitely able to reliably reproduce this with the given config for It's possible that this is specific to the VSCode integration, somehow (as I tested + reproduced this only in VSCode). |
Okay finally took a look at this, and it makes sense why this is happening. You are telling VSCode, and rust-analyzer therefor that there are 5 projects via the folders setting, all of these are cargo workspaces that belong to the main |
@Veykril Hmmm any hint as to the difference in behavior between 2018 crates and 2021 crates? Are you saying we have to bring it up to the cargo team? |
#14571 related |
The editions shouldn't matter here (and if they did it would still be a r-a issue, not cargo), and in fact the linked issue is basically the same as I described in my comment earlier so this can technically be closed. The regex case described in this issue should work properly now (that is only spawn on cargo check). Would need to double check that it is fixed in the regex case though before closing this issue. |
rust-analyzer version: rust-analyzer version: 1.65.0-nightly (bc4b39c 2022-08-29)
rustc version: (eg. output of
rustc -V
)rustc 1.58.0-nightly (891ca5f63 2021-11-15)
relevant settings: (eg. client settings, or environment variables like
CARGO
,RUSTUP_HOME
orCARGO_HOME
)Env (pulled from
cargo check
process):Editor configuration (VSCode workspace):
Description
Hi! I am using rust-analyzer with a large, multi-language monorepo, which includes several crates spanning several editions: mostly 2018, but with a small number of 2021 crates. With this, we distribute a VSCode multi-root workspace configuration, that aims to suit most developers' needs across different languages. In this configuration, each top-level project is declared as a
folder
in the VSCode workspace.When I open our workspace, rust-analyzer does some initial processing, and will then start 3
cargo check
processes. These are all invoked with the--all-targets
flag, and are run from the root directory of our workspace, i.e. they are all invoked with:With the number of subcrates we have, this becomes a rather slow operation.
We've also observed that the number of redundant checks is proportional to the number of
edition = 2021
crates we have asfolders
in our VSCode workspace.folder
s, we see only a singlecargo check
process, and 477 files being indexed by RA.folder
, we see 2cargo check
s, and 954 (2x) files being indexed, andcargo check
s and 1431 (3x) files being indexed.(NOTE:
cargo check
is absent from the above, because it finished before my screenshot captured)Reproduction
I can't share the full source repository, though I've found a similar repro on an OSS repository. In this case, rust-analyzer will start multiple
cargo check
s, also with the same redundant behaviour, but this doesn't appear to be affected by mixing and matching editions.relevant settings
header above.Expected result: A single

cargo check
is run for the workspaceActual result: Multiple
cargo check
s are run for the workspace.Further analysis
I wrote a small script to collect information about my running
cargo check
processes to better understand what was going on. This confirmed that these processes had identical command line args, PWD and environment variables - I've included it below.The text was updated successfully, but these errors were encountered: