]> git.lizzy.rs Git - rust.git/commitdiff
Merge #9558
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>
Mon, 26 Jul 2021 14:53:05 +0000 (14:53 +0000)
committerGitHub <noreply@github.com>
Mon, 26 Jul 2021 14:53:05 +0000 (14:53 +0000)
9558: Do not erase Cargo diagnostics from the closed documents r=matklad a=SomeoneToIgnore

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/6850

The LSP specification at https://microsoft.github.io/language-server-protocol/specifications/specification-3-14/#textDocument_publishDiagnostics states that

> Diagnostics notification are sent from the server to the client to signal results of validation runs.
>
> Diagnostics are “owned” by the server so it is the server’s responsibility to clear them if necessary. The following rule is used for VS Code servers that generate diagnostics:
>
>  *  if a language is single file only (for example HTML) then diagnostics are cleared by the server when the file is closed.
>  *  if a language has a project system (for example C#) diagnostics are not cleared when a file closes. When a project is opened all diagnostics for all files are recomputed (or read from a cache).
>
> When a file changes it is the server’s responsibility to re-compute diagnostics and push them to the client. If the computed set is empty it has to push the empty array to clear former diagnostics. Newly pushed diagnostics always replace previously pushed diagnostics. There is no merging that happens on the client side.

So for projects we should not clear any diagnostics from cargo/json projects.
Our "standalone file" mode is in a way a project too, with sysroot attached and a potential support for dynamic standalone files.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
1  2 
crates/rust-analyzer/src/main_loop.rs

Simple merge