rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Constant "cargo check" invalidation

Open andrewbaxter opened this issue 1 year ago • 1 comments

I searched around a lot, and there are other people reporting similar issues, but I think this stands alone because I've ruled out all the other mentioned issues AFAIK.

In short: every time I save, including after very minor changes, cargo check runs (expected) and checks all dependencies (unexpected) taking several minutes. To my knowledge this didn't always happen.

I run 1 instance of VS code, and I set

  "rust-analyzer.cargo.extraEnv": {
    "CARGO_TARGET_DIR": "/mnt/scratch/ra_cargo_target"
  },
  "rust-analyzer.check.extraEnv": {
    "CARGO_TARGET_DIR": "/mnt/scratch/ra_cargo_target"
  }

which is used only by rust-analyzer. I don't run cargo, or any other external processes on rust code. This happens when I make a change, save, then change the line very slight, and save again (i.e. at most a few seconds between invocations).

Here's a list of things people have suggested:

  • Different RUSTFLAGS (nothing in my env var, but every run should be consistent since it's all a single RA process)
  • Different pkgconfig env vars (single RA process, same as above)
  • Background process invalidating things (not running cargo watch or other vs code instances)
  • Sharing a cache with a different target (AFAIK cargo writes to different dirs for different targets, but again this is all a single RA process so unless it's invalidating itself I don't see how it could be invalidated)

FWIW the vs code workspace does have mixed targets - x86 and wasm, with one local package shared between them.

andrewbaxter avatar Feb 15 '24 12:02 andrewbaxter

Ah... I inspired myself and just tried running vs code in the web directory rather than at the top of the project and the constant invalidations disappeared. Is it possible that it was invalidating itself as it ran?

The only other relevant setting I can think of is

  "rust-analyzer.linkedProjects": [
    "rust/native/Cargo.toml",
    "rust/shared/Cargo.toml",
    "rust/web/Cargo.toml"
  ],

since the projects were nested several levels deep.

Also I think I was having issues getting it to detect --cfg=web_sys_unstable_apis in config.toml so I added

  "rust-analyzer.runnableEnv": {
    "RUSTFLAGS": "--cfg=web_sys_unstable_apis"
  },

Edit: editor claims that wasn't a valid config so it probably was ignored, so probably irrelevant.

andrewbaxter avatar Feb 15 '24 12:02 andrewbaxter