rust-lang / rust-analyzer

A Rust compiler front-end for IDEs
https://rust-analyzer.github.io/
Apache License 2.0
13.98k stars 1.55k forks source link

Regression: Diagnostics not clearing after fix and save #17300

Closed tomjw64 closed 2 months ago

tomjw64 commented 2 months ago

This seems to be a regression from the last released version of the rust-analyzer extension. When the file is saved, diagnostics will appear, but then if problem is fixed and saved again, the diagnostics will remain. The extension must be restarted to clear diagnostics.

This only occurs on the newest version of rust-analyzer. When testing on 0.3.1958, this issue does not occur. I suspect it has something to do with this PR.

rust-analyzer version: 2024-05-27

rustc version: rustc 1.80.0-nightly (bdbbb6c6a 2024-05-26)

editor or extension: VSCode, extension version 0.3.1975

example video of issue: https://github.com/rust-lang/rust-analyzer/assets/1285308/9dee3798-cddd-4e76-9a11-e49cfd510cca

kalkronline commented 2 months ago

Was just about to file this. For me, this is only happening over SSH.

mladedav commented 2 months ago

Looking at this, what I just noticed could cause this is if the next flycheck gets cancelled, the diagnostics are not cleared. But I don't think that should happen too often so probably not the issue?

I'll try to look if I can replicate it (maybe with ssh), but does it happen for you with all projects? Or just some specific ones?

jlvihv commented 2 months ago

I also encountered this issue. The problem started after upgrading to the latest version of rust-analyzer yesterday afternoon. I encountered this issue on both VSCode and Zed.

jlvihv commented 2 months ago

Was just about to file this. For me, this is only happening over SSH.

It might be because your local and remote environments are using different versions of the rust-analyzer extension. Once you upgrade them to the latest version, you will encounter the same issue.

liam-b commented 2 months ago

I'm having the exact same issue on my local vscode. Errors don't seem to get cleared after fixing the code. (just to confirm, I downgraded to v0.3.1958 and all is well)

Veykril commented 2 months ago

Right, I can tell the issue. If you have check on save diagnostics somewhere and the next check succeeds without emitting any again we won't clear them as the logic only does when a diagnostic was received :facepalm:

mladedav commented 2 months ago

@Veykril It should get cleared when we receive DidFinish?

Veykril commented 2 months ago

Right, it's in fact the other way around, we don't clear it if a succeeding check still has diagnostics (that is we accumulate), which is what one can observein the linked example video (the test function is unused and hence always emits a warning)

mladedav commented 2 months ago

If a check has diagnostics, the old ones should be cleared when the first AddDiagnostic is received so in that example when the unused function diagnostics is received, all other should disappear.

The state is tracked for flychecks globally though, so if there are invocations per workspace, that would be broken as the first finishing flycheck would clear its (potentially empty) diagnostics and the other flychecks would accumulate.

vctorized commented 2 months ago

I also encountered this issue. The problem started after upgrading to the latest version of rust-analyzer yesterday afternoon. I encountered this issue on both VSCode and Zed.

temporary fix for zed: set rust-analyzer binary in your settings.json to the rustup rust-analzyer as follow: "lsp": { "rust-analyzer": { "binary": { "path": "/Users/[ur_user_name]/.cargo/bin/rust-analyzer", "arguments": [] } } } then switch your rustup to a stable version (e.g. 1.78.0) and restart zed editor

mladedav commented 2 months ago

set rust-analyzer binary in your settings.json to the rustup rust-analzyer

Note that rust-analyzer is not installed by rustup when you use the default profile, you need to add the component manually if you haven't yet.

lnicola commented 2 months ago

Fixed in https://github.com/rust-lang/rust-analyzer/pull/17302.