-
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
Seemingly incompatible design between rust-project.json and checkOnSave.overrideCommand #13437
Comments
your second point will be fixed by config interpolation/substitution support, see #13297. I'm currently thinking about how what to use a interpolation syntax and the like. |
I'm still a bit unclear on the details - what specifically do you envision being interpolatable that will solve this issue? Something like |
Basically we would expose some kind of interpolation var that when used will change how we invoke the command (you already took a look at #13128 it seems). It's very good timing that you are raising this for rust-project.json now and not later as well, so I can incorporate that into my brainstorming :). In #13128 the behaviors of how we invoke it are basically gonna be, run command once in the root dir, per workspace in the root with the manifest path if the variable was used or per workspace in the workspace dir. From my understanding here Of course things would change if we allow multiple rust-project.json, though I'd have to look into that first to know if that is actually something we want to have. |
To be on the same page, I'm making the following assumptions about what things mean (please do correct me!): root - the working directory of the I guess from the things you mentioned I would need Maybe I'm missing something about I guess the I guess in some workflows it is also sensible to check all of the files everywhere in the project at once (so you immediately get an overview of all the errors in a project), which we can already do today, but again, would be slow. EDIT: I now realise that due to there being only one workspace in the |
This doesn't really make sense though, what would r-a pass to bazel? If we only invoke the command once there is no dynamic data at play here, at which point you can just encode whatever your check command needs in the additional args.
Ah, so you want the file path of whatever file was saved. That would be something we could add as an interpolation var for
A manifest file would be the Thanks for clarifying these things, this is really helpful in figuring things out here :) |
My project runs clippy on the entire (8000 crate) codebase. The first run is slow (obviously), but afterwards it's surprisingly fast to run clippy across that many targets. |
Thanks for the very quick responses! Your last comment wrt the file path of the saved file being available as an interpolation variable is spot on with what I was envisioning as a concrete solution. I'll proceed with my prototype implementation that just builds everything for now, and hopefully I can get a lucky repeat of what @woody77 encountered with only the first run taking a lot of time. |
Coming back to this (I am currently digging into ProjectJson a bit to understand how it works better)
A |
What do
mean? Most likely I'm missing something, but I don't see how you can have multiple |
A cargo workspace is a collection of crates which share a lockfile for dependency resolution and the target/ build directory. You can build all crates in a cargo workspace by passing |
If your workspaces depend on each other, you'll have to list the dependencies and crates explicitly for both, that is you'll have to repeat yourself for the crates that are used in multiple workspaces as |
@Veykril, as per your comment here - #13297 (comment), would you accept a patch adding very small bits of interpolation, likely only path to the file that was just saved? I think that would be enough for the |
I have already opened #13528 which adds parts of this. Not the |
There could be a |
Ye, that is a third option. I was hoping not to having to split the thing into two but we might have to as it does sound the most sensible without losing functionality. |
The initial diagnostics run probably shouldn't be "initialCheckOnSave", but something like |
For 1, as rust-project.json is essentially a reflection of the global "Project" in-memory structure of rust-analyzer, there should be only one of those. But it's totally valid to write some logic somewhere which would dynamically piece together rust-project.json required for some specific subview into the monorepo. I've explaing this a bit here: #13941 |
For 2., I would suggest these three approaches to solve the "checkOnSave with bazel" class of problems, in the order of their technical soundness (which might not correspond to the order according to the immediate UX)
|
This is getting slightly off-topic, but I'm interested in what you said:
Does rust-analyzer not use some of the diagnostics that cargo/rustc report in order to drive things, e.g. if cargo/rustc reports something like "unknown identifier", does rust-analyzer not then try to suggest an "import missing identifier" action? I'm curious because this is basically how haskell-language-server and ghc work together - ghc reports errors and HLS basically parses those errors into code actions/code lenses. In there, the only role of the build system is to provide a working ghc session with all the necessary loaded packages, i.e. there is no dependency on the underlying build system beyond that. |
Rustc actually creates these suggestions on it's own. It exposes them in a machine readable way when using the json error format to allow other tools like |
If all you do is runing compiler and displaying its errors, the LSP is conceptually not necessary. What you rather want is just some common JSON format for rich error messages with multiple spans, fixits and what not. So, the editor just runs the build system, parses errors, and displays all bells and whistles in editor, without requiring any kind of persistent process, and without knowing any details about the editor. Sadly, we don't have such common JSON format, but we do have LSP, which creates the pressure to pipe everything through LSP, even though it could have been a good old UNIX style batch process. |
Just wanted to poke at this, coming from related issue #14217. I'm not sure what the takeaway is from this conversation. Is I'm trying to use |
The agreement seems to be that the |
It doesn't look like the BSP supports passing compilation errors to the client in a common format. Nor does it differentiate between compiling and typechecking. These just seem like missing features though. I've opened an issue here: build-server-protocol/build-server-protocol#646 |
Hey all!
I have a couple of questions:
Cargo.toml
files spread across multiple folders, you only use onerust-project.json
?checkOnSave.overrideCommand
)? For example, passing it as an argument tocheckOnSave.overrideCommand
.My personal investigation has reached "yes, you should have only one rust-project.json" for 1.:
rust-project.json
you reference deps with their index in the array for the samerust-project.json
file, and I don't know how this could be compatible with multiplerust-project.json
srust-analyzer
with multiplerust-project.json
s doesn't work - e.g. crossrust-project.json
goto def doesn't workand "no" for 2.:
checkOnSave.extraEnv
are passed, which both appear to be staticThis combination is very unfortunate, because now, there is no way for the tool that's going to be used instead of
cargo check
to know what it should be building - in a huge repo, this is not viable.I assume that when we're using
cargo
this "what should I build" issue is resolved by the fact thatcargo check
is run in the root of the workspace, which is determined by aCargo.toml
file. However, in therust-project.json
, this is no longer a solution, because we can have only onerust-project.json
file, hence in order to be correct, the only thingcheckOnSave.overrideCommand
could do is build everything in the workspace.My proposed solutions are to do one of
checkOnSave.overrideCommand
(seems to be much easier)rust-project.json
files - seems to be much more difficult to implement, but perhaps it's a better approach in the long run, so that the assumptions made for cargo based projects are also valid forrust-project.json
based ones?I would be happy to implement some version of "fix" 2., if we could come to an agreement on what that would be.
Context:
I'm trying to implement diagnostics support for
rust-analyzer
+rules_rust
, which relies oncheckOnSave.overrideCommand
/cargo check
.The text was updated successfully, but these errors were encountered: