rust-lang / rust-lang/rust-analyzer
Seemingly incompatible design between rust-project.json and checkOnSave.overrideCommand
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
Hey all!
I have a couple of questions:
- Is it expected that in a code base where with Cargo you would have many
Cargo.tomlfiles spread across multiple folders, you only use onerust-project.json? - Is there a way to give some info on what file we want to "cargo check" (i.e. what file triggered the invocation of
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.:
- in
rust-project.jsonyou reference deps with their index in the array for the samerust-project.jsonfile, and I don't know how this could be compatible with multiplerust-project.jsons - trying to run
rust-analyzerwith multiplerust-project.jsons doesn't work - e.g. crossrust-project.jsongoto def doesn't work
and "no" for 2.:
- it seems that nothing dynamic is passed to the executable when it's run (in the source code) - only the presupplied args and the environment from
checkOnSave.extraEnvare passed, which both appear to be static
This 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 that cargo check is run in the root of the workspace, which is determined by a Cargo.toml file. However, in the rust-project.json, this is no longer a solution, because we can have only one rust-project.json file, hence in order to be correct, the only thing checkOnSave.overrideCommand could do is build everything in the workspace.
My proposed solutions are to do one of
- "fix" 2. so that we pass some info to
checkOnSave.overrideCommand(seems to be much easier) - "fix" 1. to allow autodiscovery and combining of
rust-project.jsonfiles - 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.jsonbased 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 on checkOnSave.overrideCommand/cargo check.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review how rust-project.json and checkOnSave.overrideCommand are handled, including the configuration used for rules_rust diagnostics. Clarify whether multiple project files or dynamic information about the triggering file should be supported, then define the agreed behavior and validation needed before implementing it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100