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

Can't specify features for individual crates in a virtual workspace #5383

Closed
Michael-F-Bryan opened this issue Jul 15, 2020 · 5 comments
Closed
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@Michael-F-Bryan
Copy link
Contributor

When you have a workspace containing multiple crates in subdirectories and those crates have their own feature flags, it's not possible to specify which feature flags to use when checking/navigating that project.

Setting rust-analyzer.cargo.features doesn't work because cargo errors with "error: --features is not allowed in the root of a virtual workspace", same as if I ran cargo check --features foo from the workspace root.

This becomes particularly evident if you are continuously recompiling and running tests in a background terminal (e.g. cd sub-crate && cargo watch -x "check --features foo"). Rust Analyzer ends up compiling the crate/workspace without the feature and cargo watch compiles with it. That means you'll constantly be rebuilding the entire crate... Which can be quite expensive when the feature flag enables several transitive dependencies (e.g. tokio and a HTTP server).

@matklad
Copy link
Member

matklad commented Jul 15, 2020

If you are running cargo watch anyway, you should set rust-analyzer.checkOnSave.enable: false. Cargo watch should still provide you with inline error markers, via the problem matcher.

@Michael-F-Bryan
Copy link
Contributor Author

Cargo watch should still provide you with inline error markers, via the problem matcher

Does the problem matcher need cargo watch to be running inside a VS Code terminal? I run cargo watch completely separately from VS Code, and when I disabled checkOnSave and restarted VS Code it didn't show me any inline error messages.

@matklad
Copy link
Member

matklad commented Jul 15, 2020

You need to run it as a vscode task, the following definition should work

    {
      "label": "Watch",
      "group": "build",
      "type": "shell",
      "command": "cargo watch --package rust-analyzer",
      "problemMatcher": "$rustc-watch",
      "isBackground": true
    },

@jonas-schievink
Copy link
Contributor

This is a Cargo limitation that will be addressed by rust-lang/rfcs#2957.

@flodiebold flodiebold added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Dec 22, 2020
@matklad
Copy link
Member

matklad commented May 22, 2021

I belive this was fixed on the cargo side with the introduction of resolver=2

@matklad matklad closed this as completed May 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

4 participants