Skip to content
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

rust-analyzer doesn't fully respect CARGO_TARGET_DIR set with rust-analyzer.server.extraEnv #12760

Open
willhodges opened this issue Jul 13, 2022 · 5 comments
Labels
C-support Category: support questions

Comments

@willhodges
Copy link

willhodges commented Jul 13, 2022

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 (5342f47 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

@flodiebold
Copy link
Member

I don't know how the configuration works in Atom, but VSCode isn't going to respect settings in a rust-analyzer.json. You need to put the settings inside a .vscode/settings.json (and in flattened form, not nested like in your file). Also, server.extraEnv is a setting specific to the VSCode extension. Other extensions might have different ways to configure the environment.

@willhodges
Copy link
Author

willhodges commented Jul 15, 2022

@flodiebold

I don't know how the configuration works in Atom, but VSCode isn't going to respect settings in a rust-analyzer.json.

This doesn't appear to be correct. If you pull down the project and open it in VSCode, rust-analyzer runs and target/check is populated. The only place that dir is specified is in rust-analyzer.json. target/debug is also populated, which suggests the environment variable is not respected somewhere along the way.

Also, server.extraEnv is a setting specific to the VSCode extension. Other extensions might have different ways to configure the environment.

I'm fine with using VSCode for the repro, since it seems to be one of the more popular editors for Rust.

@flodiebold
Copy link
Member

This doesn't appear to be correct. If you pull down the project and open it in VSCode, rust-analyzer runs and target/check is populated. The only place that dir is specified is in rust-analyzer.json. target/debug is also populated, which suggests the environment variable is not respected somewhere along the way.

That's not the case for me. Maybe you have the target dir configured somewhere else as well? Do you have any global VSCode settings for rust-analyzer?

@willhodges
Copy link
Author

I don't believe so. I can try to test this in a clean VM later this weekend.

@flodiebold
Copy link
Member

You could also try changing the path configured in rust-analyzer.json to something else (e.g. target/check2) and see what happens.

@flodiebold flodiebold added the C-support Category: support questions label Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

2 participants