rust-analyzer icon indicating copy to clipboard operation
rust-analyzer copied to clipboard

rustc json diagnostics parsing error

Open TimovVeen opened this issue 7 months ago • 7 comments

rust-analyzer version: 0.3.2490-standalone

rustc version: 1.87.0

editor or extension: Helix / Neovim (any lsp client)

I am trying to get diagnostics to work on a project without cargo. Meson does support clippy output via clippy-driver, so I changed the check.overrideCommand, however, rust-analyzer fails with: ERROR synthetic syntax. Looking at the json output of cargo clippy and clippy-driver/rustc, they seem to be structured slightly differently: json outputs

I can reproduce the issue with a simple main.rs containing an unused variable and setting check.overrideCommand to rustc src/main.rs --emit metadata --out-dir /tmp --error-format=json

TimovVeen avatar Jun 14 '25 15:06 TimovVeen

The synthetic syntax error is not related. Is that the only error you see?

ChayimFriedman2 avatar Jun 14 '25 18:06 ChayimFriedman2

Yes that's the only thing that gets logged, and no diagnostics show up in the editor

TimovVeen avatar Jun 14 '25 18:06 TimovVeen

So there is no problem?

ChayimFriedman2 avatar Jun 14 '25 18:06 ChayimFriedman2

The problem is that the output from rustc/clippy-driver doesn't show up as inline diagnostics in lsp clients, and it does when the json output comes from cargo check (default).

TimovVeen avatar Jun 14 '25 18:06 TimovVeen

The difference in the structure does seem like something that will cause us to fail to parse it, although I'm not sure.

ChayimFriedman2 avatar Jun 14 '25 19:06 ChayimFriedman2

I've tested some more editors, the rustc output fails to show diagnostics for Helix, Neovim, and Zed. However it does seem to work for vscode. So maybe the json does get parsed correctly, but rust-analyzer outputs a message to the client that can only be properly understood by vscode. I don't know how to debug the client-server messages though.

TimovVeen avatar Jun 14 '25 19:06 TimovVeen

There are extensions that allow you to see the LSP communication, at least to VSCode, I think.

ChayimFriedman2 avatar Jun 14 '25 19:06 ChayimFriedman2