rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

Activate features of individual crates in a cargo workspace

Open Lucretiel opened this issue 4 years ago • 2 comments

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.

Lucretiel avatar Sep 20 '21 21:09 Lucretiel

Note that there's the same issue with cargo.noDefaultFeatures which doesn't work in a cargo workspace.

ia0 avatar Mar 17 '22 11:03 ia0

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. Screenshot 2022-07-31 at 13 14 52

shadeglare avatar Jul 31 '22 10:07 shadeglare

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.features features 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.features or some new config - ie allow a mapping of Cargo.toml paths to features
  • Allow us to choose features through the UI like in CLion

dhedey avatar Mar 18 '23 17:03 dhedey

https://github.com/rust-lang/rust-analyzer/pull/14910 addresses this for single workspace projects. Multi workspaces still suffer here

Veykril avatar May 26 '23 20:05 Veykril

#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.

Lucretiel avatar May 26 '23 20:05 Lucretiel

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.

Veykril avatar May 26 '23 20:05 Veykril