diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index d94d9cb51d..a12a521347 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -49,8 +49,8 @@ use language::{ }; use lsp::DiagnosticSeverity; use multi_buffer::{ - Anchor, AnchorRangeExt, MultiBuffer, MultiBufferPoint, MultiBufferRow, MultiBufferSnapshot, - RowInfo, ToOffset, ToPoint, + Anchor, AnchorRangeExt, ExcerptId, MultiBuffer, MultiBufferPoint, MultiBufferRow, + MultiBufferSnapshot, RowInfo, ToOffset, ToPoint, }; use serde::Deserialize; use std::{ @@ -574,6 +574,21 @@ impl DisplayMap { self.block_map.read(snapshot, edits); } + pub fn remove_inlays_for_excerpts(&mut self, excerpts_removed: &[ExcerptId]) { + let to_remove = self + .inlay_map + .current_inlays() + .filter_map(|inlay| { + if excerpts_removed.contains(&inlay.position.excerpt_id) { + Some(inlay.id) + } else { + None + } + }) + .collect::>(); + self.inlay_map.splice(&to_remove, Vec::new()); + } + fn tab_size(buffer: &Entity, cx: &App) -> NonZeroU32 { let buffer = buffer.read(cx).as_singleton().map(|buffer| buffer.read(cx)); let language = buffer diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index c5fce0da01..1f7484c7e4 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -4170,10 +4170,13 @@ impl Editor { if let Some(InlaySplice { to_remove, to_insert, - }) = self.inlay_hint_cache.remove_excerpts(excerpts_removed) + }) = self.inlay_hint_cache.remove_excerpts(&excerpts_removed) { self.splice_inlays(&to_remove, to_insert, cx); } + self.display_map.update(cx, |display_map, _| { + display_map.remove_inlays_for_excerpts(&excerpts_removed) + }); return; } InlayHintRefreshReason::NewLinesShown => (InvalidationStrategy::None, None), diff --git a/crates/editor/src/inlay_hint_cache.rs b/crates/editor/src/inlay_hint_cache.rs index fd419b2968..1e22487500 100644 --- a/crates/editor/src/inlay_hint_cache.rs +++ b/crates/editor/src/inlay_hint_cache.rs @@ -555,12 +555,12 @@ impl InlayHintCache { /// Completely forget of certain excerpts that were removed from the multibuffer. pub(super) fn remove_excerpts( &mut self, - excerpts_removed: Vec, + excerpts_removed: &[ExcerptId], ) -> Option { let mut to_remove = Vec::new(); for excerpt_to_remove in excerpts_removed { - self.update_tasks.remove(&excerpt_to_remove); - if let Some(cached_hints) = self.hints.remove(&excerpt_to_remove) { + self.update_tasks.remove(excerpt_to_remove); + if let Some(cached_hints) = self.hints.remove(excerpt_to_remove) { let cached_hints = cached_hints.read(); to_remove.extend(cached_hints.ordered_hints.iter().copied()); } diff --git a/crates/multi_buffer/src/anchor.rs b/crates/multi_buffer/src/anchor.rs index 9c1fe75e99..9e28295c56 100644 --- a/crates/multi_buffer/src/anchor.rs +++ b/crates/multi_buffer/src/anchor.rs @@ -71,7 +71,7 @@ impl Anchor { if self_excerpt_id == ExcerptId::min() || self_excerpt_id == ExcerptId::max() { return Ordering::Equal; } - if let Some(excerpt) = snapshot.excerpt(self.excerpt_id) { + if let Some(excerpt) = snapshot.excerpt(self_excerpt_id) { let text_cmp = self.text_anchor.cmp(&other.text_anchor, &excerpt.buffer); if text_cmp.is_ne() { return text_cmp; diff --git a/crates/multi_buffer/src/multi_buffer.rs b/crates/multi_buffer/src/multi_buffer.rs index 2a4c558b5a..0dd0d480ec 100644 --- a/crates/multi_buffer/src/multi_buffer.rs +++ b/crates/multi_buffer/src/multi_buffer.rs @@ -6041,7 +6041,7 @@ impl MultiBufferSnapshot { return &entry.locator; } } - panic!("invalid excerpt id {:?}", id) + panic!("invalid excerpt id {id:?}") } }