diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 1c27e820a0..bea9bb5304 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -183,12 +183,8 @@ impl ProjectDiagnosticsEditor { }); cx.emit(EditorEvent::TitleChanged); - if this.editor.focus_handle(cx).contains_focused(window, cx) || this.focus_handle.contains_focused(window, cx) { - log::debug!("diagnostics updated for server {language_server_id}, paths {paths:?}. recording change"); - } else { - log::debug!("diagnostics updated for server {language_server_id}, paths {paths:?}. updating excerpts"); - this.update_stale_excerpts(window, cx); - } + log::debug!("diagnostics updated for server {language_server_id}, paths {paths:?}. updating excerpts"); + this.update_stale_excerpts(window, cx); } _ => {} }); @@ -232,6 +228,7 @@ impl ProjectDiagnosticsEditor { } } EditorEvent::Blurred => this.update_stale_excerpts(window, cx), + EditorEvent::Saved => this.update_all_excerpts(window, cx), _ => {} } }, @@ -423,7 +420,10 @@ impl ProjectDiagnosticsEditor { cx: &mut Context, ) -> Task> { let was_empty = self.multibuffer.read(cx).is_empty(); - let buffer_snapshot = buffer.read(cx).snapshot(); + let buffer_ = buffer.read(cx); + let is_dirty = buffer_.is_dirty(); + let buffer_snapshot = buffer_.snapshot(); + let buffer_id = buffer_snapshot.remote_id(); let max_severity = if self.include_warnings { lsp::DiagnosticSeverity::WARNING @@ -536,6 +536,7 @@ impl ProjectDiagnosticsEditor { buffer.clone(), &buffer_snapshot, excerpt_ranges, + is_dirty, cx, ) }); diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index e27cbf868a..4a101c32cb 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -1586,7 +1586,14 @@ impl MultiBuffer { }; let buffer_snapshot = buffer.read(cx).snapshot(); - self.update_path_excerpts(path.clone(), buffer, &buffer_snapshot, merged_ranges, cx); + self.update_path_excerpts( + path.clone(), + buffer, + &buffer_snapshot, + merged_ranges, + false, + cx, + ); } } @@ -1610,6 +1617,7 @@ impl MultiBuffer { &buffer_snapshot, new, counts, + false, cx, ) } @@ -1620,6 +1628,7 @@ impl MultiBuffer { buffer: Entity, buffer_snapshot: &BufferSnapshot, excerpt_ranges: Vec>, + keep_excerpts: bool, cx: &mut Context, ) -> (Vec>, bool) { let (new, counts) = Self::merge_excerpt_ranges(&excerpt_ranges); @@ -1630,6 +1639,7 @@ impl MultiBuffer { buffer_snapshot, new, counts, + keep_excerpts, cx, ) } @@ -1664,6 +1674,7 @@ impl MultiBuffer { &buffer_snapshot, new, counts, + false, cx, ); ranges @@ -1682,10 +1693,11 @@ impl MultiBuffer { buffer_snapshot: &BufferSnapshot, new: Vec>, counts: Vec, + keep_excerpts: bool, cx: &mut Context, ) -> (Vec>, bool) { let (excerpt_ids, added_a_new_excerpt) = - self.update_path_excerpts(path, buffer, buffer_snapshot, new, cx); + self.update_path_excerpts(path, buffer, buffer_snapshot, new, keep_excerpts, cx); let mut result = Vec::new(); let mut ranges = ranges.into_iter(); @@ -1734,6 +1746,7 @@ impl MultiBuffer { buffer: Entity, buffer_snapshot: &BufferSnapshot, new: Vec>, + keep_excerpts: bool, cx: &mut Context, ) -> (Vec, bool) { let mut insert_after = self @@ -1818,8 +1831,20 @@ impl MultiBuffer { match (new, existing) { (None, None) => break, (None, Some((existing_id, _))) => { - existing_iter.next(); - to_remove.push(existing_id); + if keep_excerpts { + self.insert_excerpts_with_ids_after( + insert_after, + buffer.clone(), + mem::take(&mut to_insert), + cx, + ); + insert_after = existing_iter.next().unwrap(); + excerpt_ids.push(insert_after); + new_iter.next(); + } else { + existing_iter.next(); + to_remove.push(existing_id); + } continue; } (Some(_), None) => {