Skip to content

Commit 5cd7a0f

Browse files
Merge #7704
7704: Avoid transmitting unchanged diagnostics r=matklad a=michalmuskala Reading through the code for diagnostics and observing debug logs, I noticed that diagnostics are transmitted after every change for every opened file, even if they haven't changed (especially visible for files with no diagnostics). This change avoids marking files as "changed" if diagnostics are the same to what was already sent before. This will only work if diagnostics are always produced in the same order, but from my limited testing it seems this is the case. Co-authored-by: Michał Muskała <[email protected]>
2 parents 2920e7b + 528a0bc commit 5cd7a0f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

crates/rust-analyzer/src/diagnostics.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ impl DiagnosticCollection {
6565
file_id: FileId,
6666
diagnostics: Vec<lsp_types::Diagnostic>,
6767
) {
68+
if let Some(existing_diagnostics) = self.native.get(&file_id) {
69+
if existing_diagnostics.len() == diagnostics.len()
70+
&& diagnostics
71+
.iter()
72+
.zip(existing_diagnostics)
73+
.all(|(new, existing)| are_diagnostics_equal(new, existing))
74+
{
75+
return;
76+
}
77+
}
78+
6879
self.native.insert(file_id, diagnostics);
6980
self.changes.insert(file_id);
7081
}

0 commit comments

Comments
 (0)