Batch diagnostics updates (#35794)

Diagnostics updates were programmed in Zed based off the r-a LSP push
diagnostics, with all related updates happening per file.

https://github.com/zed-industries/zed/pull/19230 and especially
https://github.com/zed-industries/zed/pull/32269 brought in pull
diagnostics that could produce results for thousands files
simultaneously.

It was noted and addressed on the local side in
https://github.com/zed-industries/zed/pull/34022 but the remote side was
still not adjusted properly.

This PR 

* removes redundant diagnostics pull updates on remote clients, as
buffer diagnostics are updated via buffer sync operations separately
* batches all diagnostics-related updates and proto messages, so
multiple diagnostic summaries (per file) could be sent at once,
specifically, 1 (potentially large) diagnostics summary update instead
of N*10^3 small ones.

Buffer updates are still sent per buffer and not updated, as happening
separately and not offending the collab traffic that much.

Release Notes:

- Improved diagnostics performance in the collaborative mode
This commit is contained in:
Kirill Bulatov 2025-08-07 17:45:41 +03:00 committed by GitHub
parent a5c25e0366
commit 740686b883
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 500 additions and 350 deletions

View file

@ -1,4 +1,4 @@
use std::sync::Arc;
use std::{borrow::Cow, sync::Arc};
use ::serde::{Deserialize, Serialize};
use gpui::WeakEntity;
@ -6,7 +6,7 @@ use language::{CachedLspAdapter, Diagnostic, DiagnosticSourceKind};
use lsp::{LanguageServer, LanguageServerName};
use util::ResultExt as _;
use crate::LspStore;
use crate::{LspStore, lsp_store::DocumentDiagnosticsUpdate};
pub const CLANGD_SERVER_NAME: LanguageServerName = LanguageServerName::new_static("clangd");
const INACTIVE_REGION_MESSAGE: &str = "inactive region";
@ -81,12 +81,16 @@ pub fn register_notifications(
version: params.text_document.version,
diagnostics,
};
this.merge_diagnostics(
server_id,
mapped_diagnostics,
None,
this.merge_lsp_diagnostics(
DiagnosticSourceKind::Pushed,
&adapter.disk_based_diagnostic_sources,
vec![DocumentDiagnosticsUpdate {
server_id,
diagnostics: mapped_diagnostics,
result_id: None,
disk_based_sources: Cow::Borrowed(
&adapter.disk_based_diagnostic_sources,
),
}],
|_, diag, _| !is_inactive_region(diag),
cx,
)