diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index 22a2c985ae..3ab090578d 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -54,7 +54,7 @@ use gpui::{ }; use highlight_matching_bracket::refresh_matching_bracket_highlights; use hover_popover::{hide_hover, HoverState}; -use inlay_cache::{InlayCache, InlayRefreshReason, InlaysUpdate, QueryInlaysRange}; +use inlay_cache::{InlayCache, InlayRefreshReason, InlaySplice, QueryInlaysRange}; pub use items::MAX_TAB_TITLE_LEN; use itertools::Itertools; pub use language::{char_kind, CharKind}; @@ -2605,7 +2605,7 @@ impl Editor { match reason { InlayRefreshReason::Settings(new_settings) => { - let InlaysUpdate { + let InlaySplice { to_remove, to_insert, } = self.inlay_cache.apply_settings(new_settings); @@ -2637,7 +2637,7 @@ impl Editor { .collect::>(); cx.spawn(|editor, mut cx| async move { - let InlaysUpdate { + let InlaySplice { to_remove, to_insert, } = editor diff --git a/crates/editor/src/inlay_cache.rs b/crates/editor/src/inlay_cache.rs index 71c6f6e337..d004f07491 100644 --- a/crates/editor/src/inlay_cache.rs +++ b/crates/editor/src/inlay_cache.rs @@ -70,25 +70,10 @@ struct BufferInlays { pub struct InlayId(pub usize); #[derive(Debug, Default)] -pub struct InlaysUpdate { +pub struct InlaySplice { pub to_remove: Vec, pub to_insert: Vec<(InlayId, Anchor, InlayHint)>, } -impl InlaysUpdate { - fn merge(&mut self, other: Self) { - let mut new_to_remove = other.to_remove.iter().copied().collect::>(); - self.to_insert - .retain(|(inlay_id, _, _)| !new_to_remove.remove(&inlay_id)); - self.to_remove.extend(new_to_remove); - self.to_insert - .extend(other.to_insert.into_iter().filter(|(inlay_id, _, _)| { - !self - .to_remove - .iter() - .any(|removed_inlay_id| removed_inlay_id == inlay_id) - })); - } -} pub struct QueryInlaysRange { pub buffer_id: u64, @@ -112,7 +97,7 @@ impl InlayCache { multi_buffer: ModelHandle, inlay_fetch_ranges: impl Iterator, cx: &mut ViewContext, - ) -> Task> { + ) -> Task> { let mut inlay_fetch_tasks = Vec::new(); for inlay_fetch_range in inlay_fetch_ranges { let inlays_up_to_date = self.inlays_up_to_date( @@ -203,7 +188,7 @@ impl InlayCache { })?; inlays_update } else { - InlaysUpdate::default() + InlaySplice::default() }; anyhow::Ok(updates) @@ -233,7 +218,7 @@ impl InlayCache { HashMap, OrderedByAnchorOffset)>>, ), >, - ) -> InlaysUpdate { + ) -> InlaySplice { let mut old_inlays = self.inlays_per_buffer.clone(); let mut to_remove = Vec::new(); let mut to_insert = Vec::new(); @@ -377,7 +362,9 @@ impl InlayCache { } } - InlaysUpdate { + to_insert.retain(|(_, _, new_hint)| self.allowed_hint_kinds.contains(&new_hint.kind)); + + InlaySplice { to_remove, to_insert, } @@ -386,7 +373,7 @@ impl InlayCache { pub fn apply_settings( &mut self, inlay_hint_settings: editor_settings::InlayHints, - ) -> InlaysUpdate { + ) -> InlaySplice { let new_allowed_inlay_hint_types = allowed_inlay_hint_types(inlay_hint_settings); let new_allowed_hint_kinds = new_allowed_inlay_hint_types @@ -420,7 +407,7 @@ impl InlayCache { self.allowed_hint_kinds = new_allowed_hint_kinds; - InlaysUpdate { + InlaySplice { to_remove, to_insert, }