-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Extend cargo_unsetTest to support "all" like cargo_features #11962
Conversation
This probably addresses #7225. |
Instead of having this be a seperate config flag, we should incorporate this with the already existing So with that said, I think this PR will have to wait until #12010 is being merged, then we can do this here as I don't see why we shouldn't allow disabling test for all crates if the user wishes to do so. |
Yes, it makes sense to use the same approach as in #12010 (i.e. use a single config that takes an enum instead of multiple exclusive flags, like Note however, that if we really want to revamp the config, we should probably fix how cargo arguments are handled. Right now:
I believe all cargo config should optionally take a mapping from crate to config. There's probably a way to design this nicely. There are multiple solutions and it's not clear which one is obviously better:
An important point in my opinion is that configs should always provide the way to apply to all crates (which makes it much easier to use when the cargo project is not a workspace, since it's silly to have to specify the crate name in that case). This is actually why I'm creating this PR. All cargo invocation config I need support applying to all crates ( |
thanks for raising those points, will check them out tomorrow (feel free to raise anything else regarding the config in the PR, this is the one point where we should allow ourselves to change things) |
One thing to note is that |
I see (indeed Where does rust-analyzer call into rustc/cargo to get diagnostics? I couldn't find it. |
The |
I see, but then does rust-analyzer call into |
It doesn't use the compiler. |
Oh wow, I didn't really expect that. It's a huge amount of work to duplicate parts of the compiler behavior (as well as the resulting problems like semantics divergence over time). That's good to know, thanks! |
☔ The latest upstream changes (presumably #12010) made this pull request unmergeable. Please resolve the merge conflicts. |
I tested on Emacs. I can now control rust-analyzer's behavior by editing some virtual Emacs variable with the following grammar:
(Arguments can be reordered but features must be passed with a single argument, shouldn't be hard to fix but I don't need it.) Ideally I would add |
☔ The latest upstream changes (presumably #12252) made this pull request unmergeable. Please resolve the merge conflicts. |
Sorry for the constant conflicts, had to touch up the config stuff a lot the past days :/ Will come back to this PR next week |
No problem, this PR is very small so it's very easy to fix conflicts.
Sounds good, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this seems fine to me, though given Florian's point it is somewhat questionable whether we want to do this. As was said, this entire config is kind of an escape hatch currently and ideally shouldn't exist. On the other hand given it is a thing already, I don't have a strong reason to not just accept all
here either.
crates/rust-analyzer/src/config.rs
Outdated
"Option<CargoUnsetTest>" => set! { | ||
"type": ["string", "array", "null"], | ||
"items": { "type": "string" }, | ||
"enum": ["all"], | ||
"enumDescriptions": [ | ||
"All crates are analyzed without `--cfg=test`", | ||
], | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Not sure why I had to add it before.
crates/rust-analyzer/src/config.rs
Outdated
"CargoUnsetTest" => set! { | ||
"type": ["string", "array"], | ||
"items": { "type": "string" }, | ||
"enum": ["all"], | ||
"enumDescriptions": [ | ||
"All crates are analyzed without `--cfg=test`", | ||
], | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to use anyOf
now for validity reasons in vscode, check the current version of "CargoFeatures"
of what I mean
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree it doesn't feel great to add to the debt. I would be willing to help although I'm not sure I'll have the time for the amount of effort that is needed.
In my opinion, the main issue of rust-analyzer (and also the reason why there's the unsetTest
hack) is the lack of coherence with respect to cargo+rustc. Ideally, rust-analyzer should share the same stack as cargo and rustc. By coherence, I mean that rust-analyzer should have the same opinion about the code being analyzed as cargo and rustc have when they compile/analyze it (this should be a consequence of sharing the same code, not because rust-analyzer duplicates cargo and rustc's logic because this is not maintenable). And to underline that coherence, I think rust-analyzer should provide a dynamic config describing which view of the code it is rendering. This should be expressed in the same terms as cargo and rustc. In particular, I would expect rust-analyzer to take a cargo command as config and show that. This config should be easily editable without rebooting rust-analyzer (from what I've read of the documentation, this should be already possible because the crate graph may contain multiple versions of the same crate with different configs or views in my terms). A view would be defined by everything cargo and rustc support: features, profiles, test, target, etc. I'm currently able to simulate that (module rust-analyzer restart when changing view) except for profiles (e.g. debug-assertions) but I didn't hit the issue yet. I'm able to control features, target, and now test with this PR.
Is there already an issue tracking such effort?
crates/rust-analyzer/src/config.rs
Outdated
"CargoUnsetTest" => set! { | ||
"type": ["string", "array"], | ||
"items": { "type": "string" }, | ||
"enum": ["all"], | ||
"enumDescriptions": [ | ||
"All crates are analyzed without `--cfg=test`", | ||
], | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
crates/rust-analyzer/src/config.rs
Outdated
"Option<CargoUnsetTest>" => set! { | ||
"type": ["string", "array", "null"], | ||
"items": { "type": "string" }, | ||
"enum": ["all"], | ||
"enumDescriptions": [ | ||
"All crates are analyzed without `--cfg=test`", | ||
], | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Not sure why I had to add it before.
Alright, trying to catch up on old PRs now finally. So, we actually unsert the test attribute for non-local crates since yesterday making this hack a lot less useful (its only needed for local crates now, and usually yuo don't want to use it there). So with that I am now actually inclined to not merge this, as the changes here don't really give any value anymore. Sorry for that, but thanks nevertheless for the work you put into this! |
Thanks for the feedback! I guess you're referring to #12599. Even if it still doesn't fix the problem, I agree that the problem is very minor compared to other issues rust-analyzer is facing. So it sounds good to me to close this to free some time for higher priority problems. We can get back to this when analysis is revamped to match what rust and cargo do (ideally using the same code). |
The UnsetTestCrates enum has 3 variants:
None
: Never used but equivalent toOnly(vec![])
Only
: Always used with the content ofunsetTest
All
: Never used and impossible to simulateThis PR addresses the fact that
All
is essentially impossible to reach.The use-case is that
None
andAll
are the most obvious values to produce for LSP clients since they don't know the name of the crate. This permits to have shortcuts to simply toggle tests from an LSP client without asking the user for the name of the crate.