rust-analyzer
rust-analyzer copied to clipboard
Activate features of individual crates in a cargo workspace
Currently, the only two options for cargo features in rust-analyzer are "all features" and "list of features". If you're in a cargo workspace, the "list of features" seems to apply to all crates, which breaks certain workflows when working in those crates (in particular, the "▷Run Test" inline buttons). There should be a way to apply designate specific crates to apply features in the project settings.
Note that there's the same issue with cargo.noDefaultFeatures which doesn't work in a cargo workspace.
As I understand the CLion Rust plugin has a similar ability. You can activate certain features in a crate during development.
Even if you make a reference to the crate in another crate the with different feature flags you edit the crate with the IDE pinned features of your choice.

Related to https://github.com/rust-lang/rust-analyzer/issues/8521
This is a big problem for us - we have a few mutually incompatible features (for relatively legitimate reasons) -- and a workspace with many crates with different features. But enabling any feature with eg:
"rust-analyzer.cargo.features": [
"serde",
],
Works fine when running analysis over the whole workspace*, but errors when running tests under a particular project which doesn't support that flag. As a workaround, you can add an empty dummy feature to each individual cargo project, but it's not ideal.
(*) this is not strictly true - using rust-analyzer.linkedProjects, each individual project needs to have that feature.
The following would all be sufficient fixes to serve our needs :) - in, I'm guessing, increasing order of work:
- Automatically use the requested
rust-analyzer.cargo.featuresfeatures only for projects / workspaces / crates where they are available / wouldn't error. - Allow us to choose features by Cargo.toml file in
rust-analyzer.cargo.featuresor some new config - ie allow a mapping of Cargo.toml paths to features - Allow us to choose features through the UI like in CLion
https://github.com/rust-lang/rust-analyzer/pull/14910 addresses this for single workspace projects. Multi workspaces still suffer here
#14910 addresses this for single workspace projects. Multi workspaces still suffer here
Does it? That just prevents feature abc from being enabled in crates that don't have it; it doesn't provide any way to enable abc in some crates but not others.
which breaks certain workflows when working in those crates (in particular, the "▷Run Test" inline buttons)
It fixes this scenario, I didn't realize the overall ask was for per crate feature toggles apologies.