rust-lang / rust-lang/rust-analyzer
rust-analyzer doesn't fully respect CARGO_TARGET_DIR set with rust-analyzer.server.extraEnv
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Rust-analyzer seems to kick off a cargo command in such a way that a CARGO_TARGET_DIR override set with rust-analyzer.server.extraEnv set in rust-analyzer.json in the project root. This issue popped up in trying to address issue #5828 , where rust-analyzer is invalidating my cargo cache during code analysis in a Cargo workspace with sub-crates that have different build targets.
I've made a fairly small repro case to demonstrate the issue at https://github.com/willhodges/rabug. Simply clone into the repo and then open it in VSCode (with the rust-analyzer extension) or Atom (with the ide-rust extension). The target/debug directory is immediately populated during the first rust-analyzer run despite an override of CARGO_TARGET_DIR in the project's .cargo/config. target/check is also populated, so it would seem at least some of the cargo commands rust-analyzer is running do see the override.
rust-analyzer version: rust-analyzer 0.0.0 (5342f47f4 2022-07-09)
rustc version: rustc 1.62.0 (a8314ef7d 2022-06-27)
relevant settings: See .cargo/config.toml and rust-analyzer.json in the repository above
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Clone the linked rabug reproduction and inspect its .cargo/config.toml and rust-analyzer.json settings. Open it in VSCode or Atom, observe which target directories are populated during the first rust-analyzer run, and trace the cargo commands involved. Done means CARGO_TARGET_DIR is respected consistently and the reproduction no longer populates target/debug unexpectedly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100