Hello, I'm having an issue using rust-analyzer with a rust-project.json file: my project doesn't show compilation errors/the output of cargo check when this file exists. If I remove/rename this file then my compilation errors begin to appear.
I've set up a simple hello world project that shows this issue. Its using the latest rust-analyzer (rust-analyzer d15f646ff 2021-08-30 stable as of writing). It also contains a simple Dockerfile so that the environment is (reasonably) reproducible.
I've gone through the manual and have enabled RA_LOG=rust_analyzer=info and checked the configuration and everything seems OK (check on save enabled, check on save command = check, etc), not to mention that it works completely fine with the rust-project.json file removed.
Any help on this would be greatly appreciated, thanks.
Rust-analyzer doesn't know how to invoke bazel, nor does bazel give errors in the format rust-analyzer expects. In fact I couldn't find any way to make bazel emit json formatted error messages at all in the bazel user manual. This means that you will have to use cargo one way or another. If you do use cargo, there is no need for rust-project.json at all as rust-analyzer will auto-detect the project configuration based on cargo metadata. rust-project.json exists only for projects that don't use cargo.
If you do want to use bazel, you could setup a build task in vscode to run bazel. I believe rust-analyzer has a problem matcher to extract human readable rustc error messages and show them like checkOnSave. You will have to manually run the build task though.
Thanks for helping me look into this. I don't actually need rust-analyzer to invoke Bazel, I would just like it to invoke cargo check as it usually does when the rust-project.json file doesn't exist. I've tried forcing the configuration with checkOnSave.enable = true I've also tried many other checkOnSave configurations and also tried explicitly changing the check on save command with checkOnSave.overrideCommand and pointing that back at cargo. It seems like checkOnSave is just entirely disabled when a rust-project.json file exists. Is that the case?
Managed to figure it out... Found this in the code (linking with the current commit so the reference doesn't become outdated).
So turns out that flychecks are enabled if the checkOnSave.overrideCommand configuration is explicitly set. However I had already tried that as mentioned before. Checking the type of checkOnSave_overrideCommand in config.rs gives:
A Vec<String>... so my configuration specified the string , /users/dozzman/.cargo/bin/cargo check --message-format=json. After changing that to an array in my config it began to work fine.
I didn't want to mention Bazel as I suspected it would just be a red herring -- the issue is build system agnostic. I have opened a PR which updates the documentation with my findings. Hopefully this will help other folks that come after me.