Improve support for multiple registrations of textDocument/diagnostic (#43703)

Closes https://github.com/zed-industries/zed/issues/41935

The registration ID responsible for generating each diagnostic is now
tracked. This allows us to replace only the diagnostics from the same
registration ID when a pull diagnostics report is applied.

Additionally, various deficiencies in our support for pull diagnostics
have been fixed:
- Document pulls are issued for all open buffers, not just the edited
one. A shorter debounce is used for the edited buffer. Workspace
diagnostics are also now ignored for open buffers.
- Tracking of `lastResultId` is improved.
- Stored pull diagnostics are discarded when the corresponding buffer is
closed.

Release Notes:

- Improved compatibility with language servers that use the "pull
diagnostics" feature of Language Server Protocol.

---------

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: Kirill Bulatov <kirill@zed.dev>
This commit is contained in:
John Tur
2025-12-03 20:47:43 +02:00
committed by GitHub
co-authored by Kirill Bulatov Kirill Bulatov
parent 493cfadb42
commit a51e975b81
13 changed files with 524 additions and 263 deletions
+3 -2
View File
@@ -2283,6 +2283,7 @@ impl MultiBuffer {
cx: &mut Context<Self>,
) {
use language::BufferEvent;
let buffer_id = buffer.read(cx).remote_id();
cx.emit(match event {
BufferEvent::Edited => Event::Edited {
edited_buffer: Some(buffer),
@@ -2291,8 +2292,8 @@ impl MultiBuffer {
BufferEvent::Saved => Event::Saved,
BufferEvent::FileHandleChanged => Event::FileHandleChanged,
BufferEvent::Reloaded => Event::Reloaded,
BufferEvent::LanguageChanged => Event::LanguageChanged(buffer.read(cx).remote_id()),
BufferEvent::Reparsed => Event::Reparsed(buffer.read(cx).remote_id()),
BufferEvent::LanguageChanged => Event::LanguageChanged(buffer_id),
BufferEvent::Reparsed => Event::Reparsed(buffer_id),
BufferEvent::DiagnosticsUpdated => Event::DiagnosticsUpdated,
BufferEvent::CapabilityChanged => {
self.capability = buffer.read(cx).capability();