rust-lang / rust-lang/rust-analyzer
Custom cargo paths not respected in test code-lenses
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
- VS Code extension: v0.3.1394
- rust-analyzer binary: v1.67.0
The extension currently allows specifying a custom binaries via environment variables in settings.json. Example:
"rust-analyzer.server.path": "${workspaceFolder}/bin/rust-analyzer",
"rust-analyzer.server.extraEnv": {
"CARGO": "${workspaceFolder}/bin/cargo",
"RUSTC": "${workspaceFolder}/bin/rustc",
"RUSTFMT": "${workspaceFolder}/bin/rustfmt"
},
Which I can verify it is resolved correctly when the server is initialized, by looking at the LSP traces:
"initializationOptions": {
"cargoRunner": null,
"runnableEnv": null,
"server": {
"path": "/path/to/repo/bin/rust-analyzer",
"extraEnv": {
"CARGO": "/path/to/repo/bin/cargo",
"RUSTC": "/path/to/repo/bin/rustc",
"RUSTFMT": "/path/to/repo/bin/rustfmt"
}
},
}
And reading the server code, it looks to me like they should be picked up by toolchain::cargo() by reading the environment variables:
However, when executing test code lenses like Run Test or Debug, it seems to not reuse this value, and still try to run cargo from $PATH instead:
Which results in the following error in the launched task terminal:
* Executing task: cargo test --package PACKAGE_NAME --lib --all-features -- TEST_NAME --exact --nocapture
* The terminal process failed to launch: Path to shell executable "cargo" does not exist.
Is this a bug? is there some other setting that should be configured as well?
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
Start with the linked toolchain/src/lib.rs implementation of toolchain::cargo(), then trace how test code lenses launch Run Test and Debug tasks. Reproduce with the custom CARGO setting and confirm that the launched task uses that path rather than cargo from PATH.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, vscode
- Domain
- devtools, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100