rust-analyzer: rust-analyzer.check.workspace = false is ignored on server startup

"When rust-analyzer.check.workspace" : false is set I expect that cargo check should only be run on the rust crate which I have open in vs code. However, rust-analyzer runs cargo check across all workspace members [[edit] when the server is first started. After which saving a file shows that check is only run on the crate which is opened.] This is a problem as I am working in a mono repo which has many member crates: when I’m working in one, where VS Code is only open at the member crate’s manifest directory, the rust-analyzer is slow [[edit] to start] as it is unnecessarily checking all the workspace crates.

I have reproduced this problem in a simple toy workspace.

rust-analyzer version: (eg. output of “rust-analyzer: Show RA Version” command, accessible in VSCode via <kbd>Ctrl/⌘</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>) rust-analyzer 0.3.2112-standalone

rustc version: (eg. output of rustc -V) rustc 1.77.0 (aedd173a2 2024-03-17)

editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable) VSCode version 1.93.1 38c31bc77e0dd6ae88a4e9cc93428cc27a56ba40 x64 rust-analyzer extension: v0.3.2112

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTC, RUSTUP_HOME or CARGO_HOME) in .vscode/settings.json for the workspace (user level settings.json file removed) “rust-analyzer.check.workspace”: false,

code example to reproduce: To reproduce, please see the zipped demo project: ra-workspace-issue-demo.zip

This has the structure

./
├── bar
│   ├── Cargo.toml
│   └── src
│       └── lib.rs
├── Cargo.lock
├── Cargo.toml
└── foo
    ├── Cargo.toml
    └── src
        └── lib.rs

i.e. a Cargo workspace with two workspace.member crates which do not depend on each other. In both lib.rs files, I have called a non existent function such that cargo check reports an error.

If I open, say, the foo crate: code ./foo in the problems panel, I can clearly see that rust-analyzer has reported problems in the foo crate which is not open in VS Code. (similarly I can confirm by introducing a build.rs file with panics, and the rust-analyzer output shows the error when it has built the crate it should not be running check on).

Image Screenshot showing that problems from both the foo and bar crate are being reported, despite only foo being open

[edit] Image Screenshot showing that after a save, only problems from the open crate are reported

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 36 (15 by maintainers)

Most upvoted comments

@alibektas I can confirm that it was not the case before, editing/save in that deep crate was immediate when rust-analyzer.check.workspace was false. Now, it seems like true or false value is meaningless because you’re just checking all the dependent crates. And it has really degraded my developer experience using RustRover RustAnalyzer: each save takes about 5-10 seconds… Before I was invoking cargo check for the whole workspace on demand. I think, it would be good to have the option with these values instead of just true and false: "all", "dependent_crates", "current_crate"

Update: RustRover was a typo here, I meant RustAnalyzer.

@mhnap I’m on the latest version, and still the same behavior, checking all dependent crates. Each file save takes 16-25 seconds for me…

Ah it’s probably https://github.com/rust-lang/rust-analyzer/pull/18197, you don’t have a target set (like the default). @alibektas I get a headache every time I try to think if we should have && or ||, but are you sure && is the correct call?

The current "rust-analyzer.check.workspace": false is broken in the sense that it does not do cargo check -p. To me it seems like it checks the current package and all dependent ones, and that’s why it takes a long time in a large project. This was working fine a couple of months ago, so something has changed. @alibektas Is there any plan to fix this? You created a new issue but that seems to be just there without any activity.

I did it in different tests:

  1. Save same file two times in a row (both times ran 1+ minutes)
  2. Run save (ran 1+ minutes) then run in terminal (ran under 1 second)
  3. Run save in the terminal two times in a row (both ran under 1 second)

So, for me, no matter how many times I run it via file save it takes lots of time as if it is running caro check --workspace instead of cargo check -p ...

I am not sure if this is related, but I have the following in my settings.json:

{
  "rust-analyzer.check.workspace": false
}

When I save a file, in a large project (e.g. packages/package-a/main.rs), it takes a few minutes to run the check.

However, if I run the following in a terminal for that same project, it takes one second or less:

cargo check -p package-a

Recently, I’m also observing issues with rust-analyzer.check.workspace" : false. It just checks the current crate and all the dependent crates on it. In very deep crates, it takes quite some time to check things on each save. Before, it was just changing the current crate. Has something changed recently in the behavior of this setting?