From bc076c1cc14ef219610011d212a6a0b057475b01 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Wed, 27 Oct 2021 12:39:11 +0200 Subject: [PATCH] Update display map snapshots when diagnostics are updated This is similar to what we do when we receive new parse trees from tree-sitter. --- crates/editor/src/display_map/fold_map.rs | 7 ++++++- crates/language/src/lib.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/editor/src/display_map/fold_map.rs b/crates/editor/src/display_map/fold_map.rs index efccbbbf5d..a2e6b150e7 100644 --- a/crates/editor/src/display_map/fold_map.rs +++ b/crates/editor/src/display_map/fold_map.rs @@ -204,6 +204,7 @@ pub struct FoldMap { struct SyncState { version: clock::Global, parse_count: usize, + diagnostics_update_count: usize, } impl FoldMap { @@ -225,6 +226,7 @@ impl FoldMap { last_sync: Mutex::new(SyncState { version: buffer.version(), parse_count: buffer.parse_count(), + diagnostics_update_count: buffer.diagnostics_update_count(), }), version: AtomicUsize::new(0), }; @@ -256,6 +258,7 @@ impl FoldMap { SyncState { version: buffer.version(), parse_count: buffer.parse_count(), + diagnostics_update_count: buffer.diagnostics_update_count(), }, ); let edits = buffer @@ -263,7 +266,9 @@ impl FoldMap { .map(Into::into) .collect::>(); if edits.is_empty() { - if last_sync.parse_count != buffer.parse_count() { + if last_sync.parse_count != buffer.parse_count() + || last_sync.diagnostics_update_count != buffer.diagnostics_update_count() + { self.version.fetch_add(1, SeqCst); } Vec::new() diff --git a/crates/language/src/lib.rs b/crates/language/src/lib.rs index 056661bb3f..866e182af3 100644 --- a/crates/language/src/lib.rs +++ b/crates/language/src/lib.rs @@ -63,6 +63,7 @@ pub struct Buffer { parsing_in_background: bool, parse_count: usize, diagnostics: AnchorRangeMultimap<(DiagnosticSeverity, String)>, + diagnostics_update_count: usize, language_server: Option, #[cfg(test)] operations: Vec, @@ -288,6 +289,7 @@ impl Buffer { pending_autoindent: Default::default(), language: None, diagnostics: Default::default(), + diagnostics_update_count: 0, language_server: None, #[cfg(test)] operations: Default::default(), @@ -686,6 +688,7 @@ impl Buffer { } } + self.diagnostics_update_count += 1; cx.notify(); Ok(()) } @@ -705,6 +708,10 @@ impl Buffer { }) } + pub fn diagnostics_update_count(&self) -> usize { + self.diagnostics_update_count + } + fn request_autoindent(&mut self, cx: &mut ModelContext) { if let Some(indent_columns) = self.compute_autoindents() { let indent_columns = cx.background().spawn(indent_columns); @@ -1335,6 +1342,7 @@ impl Clone for Buffer { autoindent_requests: Default::default(), pending_autoindent: Default::default(), diagnostics: self.diagnostics.clone(), + diagnostics_update_count: self.diagnostics_update_count, language_server: None, #[cfg(test)] operations: self.operations.clone(),