Stream: t-compiler/rust-analyzer

Topic: Overriding the workspace feature set


Jonas Schievink [he/him] (Jan 11 2021 at 15:03, on Zulip):

In nrf-hal, we have several facade crates that all depend on one implementation crate, each enabling a different feature of it. rust-analyzer thus will always enable every feature when editing the implementation crate (nrf-hal-common), even if this is not enabled in the settings.

Because the features aren't additive (as is common in embedded crates), this causes things to break badly when editing, so only very few modules are actually picked up by r-a. Is there any way to disable this "feature merging" from cargo metadata (I assume)? Or should I write my own project.json?

Laurențiu (Jan 11 2021 at 15:04, on Zulip):

I guess rust-analyzer.cargo.allFeatures doesn't help here?

Jonas Schievink [he/him] (Jan 11 2021 at 15:05, on Zulip):

It's already turned off

Jonas Schievink [he/him] (Jan 11 2021 at 15:12, on Zulip):

hmm, seems like I have to manually specify where all dependencies are if I make use of rust-project.json, that's not going to work

bjorn3 (Jan 11 2021 at 15:14, on Zulip):

When within a compilation graph a crate is depended on multiple times, the used feature set is the union of all the features that the individual dependent crates require. cargo metadata causes all crates in the current workspace to become part of the same compilation graph when run on a workspace Cargo.toml it seems, thus causing this feature unification.

Jonas Schievink [he/him] (Jan 11 2021 at 15:15, on Zulip):

yeah

bjorn3 (Jan 11 2021 at 15:15, on Zulip):

Same seems to happen for any member of a workspace.

Jonas Schievink [he/him] (Jan 11 2021 at 15:16, on Zulip):

I wonder if we should just add a quickfix to the unconfigured-code diagnostic that modifies the cfg flags used for analysis

Jonas Schievink [he/him] (Jan 11 2021 at 15:16, on Zulip):

With the caveat that cargo check is not affected

matklad (Jan 11 2021 at 15:36, on Zulip):

@Jonas Schievink I think, fundamentally, we need to cajole cargo metadata into behaving how we want

matklad (Jan 11 2021 at 15:37, on Zulip):

There's no good way to do that (even with the new resolver)

Jonas Schievink [he/him] (Jan 11 2021 at 15:38, on Zulip):

yeah, its behavior makes sense to me here

matklad (Jan 11 2021 at 15:38, on Zulip):

ther's a bad way though -- I believe we can cd in a specific directory

Jonas Schievink [he/him] (Jan 11 2021 at 15:39, on Zulip):

I don't think there would really be a way to run cargo check in a way that works in this workspace, other than running it once for each facade crate

matklad (Jan 11 2021 at 15:39, on Zulip):

(just -p won't work, because cargo is horrible and cwd matters)

Jonas Schievink [he/him] (Jan 11 2021 at 15:39, on Zulip):

hmm, I tried opening just nrf-hal-common in VS Code but the same happened, it's still looking at the whole workspace config

Jonas Schievink [he/him] (Jan 11 2021 at 15:40, on Zulip):

matklad said:

(just -p won't work, because cargo is horrible and cwd matters)

Hmm, this does work for cargo check at least, does cargo metadata behave differently?

matklad (Jan 11 2021 at 15:40, on Zulip):

we pass --workspace manually

matklad (Jan 11 2021 at 15:40, on Zulip):

Hmm, this does work for cargo check at least, does cargo metadata behave differently?

matklad (Jan 11 2021 at 15:41, on Zulip):

not entirely -- it'll also unify-in features of the package in cwd

matklad (Jan 11 2021 at 15:41, on Zulip):

this is no-op in virtual manifests thougt

matklad (Jan 11 2021 at 15:42, on Zulip):

so yeah, I believe we need to add code for "run cargo metadata many times and unify crate graphs"

Jonas Schievink [he/him] (Jan 11 2021 at 15:43, on Zulip):

matklad said:

not entirely -- it'll also unify-in features of the package in cwd

oh wow you're right, how odd

Jonas Schievink [he/him] (Jan 11 2021 at 15:44, on Zulip):

not looking forward to these kinds of changes, they'll probably break r-a for many users and increase memory usage a lot in some cases :sweat_smile:

matklad (Jan 11 2021 at 15:44, on Zulip):

https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/project_model/src/workspace.rs#L294-L444

matklad (Jan 11 2021 at 15:45, on Zulip):

this the "bit" where "unify metadatas" thing needs to happen

matklad (Jan 11 2021 at 15:45, on Zulip):

not looking forward to these kinds of changes, they'll probably break r-a for many users and increase memory usage a lot in some cases :sweat_smile:

matklad (Jan 11 2021 at 15:45, on Zulip):

I mean, they'll be opt-in

matklad (Jan 11 2021 at 15:46, on Zulip):

I imagine you could extend linkedProjects section to include full cargo command

matklad (Jan 11 2021 at 15:47, on Zulip):

so, for nrf-hal, you'll link each of the crates

matklad (Jan 11 2021 at 15:48, on Zulip):

actually, without "and unify crate graph", this should be easy to pull off

Last update: Jul 24 2021 at 20:30UTC