I have vscode set up with the rust-analyzer plugin and it works in most cases. I have just added an optional feature but I cannot get vscode/rust-analyzer to parse the code, instead it always shows:
code is inactive due to #[cfg] directives: std is disabled rust-analyzer (inactive-code)
Cargo.toml:
[dependencies]
rand = {version = "0.8.5", default-features = false}
[features]
std = ["rand/std"]
main.rs:
#[cfg(std)]
use rand;
fn main() {}
My settings file has these lines:
"rust-analyzer.cargo.features": "all",
"rust-analyzer.checkOnSave.features": "all"
I thought it might be related to using both a VSCode workspace and a cargo workspace but simplifying it down to a stub cargo project shows the same issue.
Finally, I followed the advice in this question (no other plugins running and enabled RA_LOGS) but the output appears to show the command I expect with --all-features
: How to activate an optional dependency?
[INFO flycheck] restart flycheck "cargo" "check" "--workspace" "--message-format=json" "--manifest-path" "$HOME/workspace/stackoverflow/Cargo.toml" "--all-targets" "--all-features"
Any idea what else I can check?