From 55ee72d84ab90c6f4b91aa25a3c9cf7f5dc799d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos?= Date: Mon, 9 Dec 2024 00:27:54 -0300 Subject: [PATCH] Simplify TextHighlights map (#21724) Remove unnecessary `Option` wrapping. --- crates/editor/src/display_map.rs | 10 +++++----- crates/editor/src/display_map/inlay_map.rs | 14 +++++++------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rs index a75c2ce9fa..2c62295a29 100644 --- a/crates/editor/src/display_map.rs +++ b/crates/editor/src/display_map.rs @@ -82,7 +82,7 @@ pub trait ToDisplayPoint { fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint; } -type TextHighlights = TreeMap, Arc<(HighlightStyle, Vec>)>>; +type TextHighlights = TreeMap>)>>; type InlayHighlights = TreeMap>; /// Decides how text in a [`MultiBuffer`] should be displayed in a buffer, handling inlay hints, @@ -434,7 +434,7 @@ impl DisplayMap { style: HighlightStyle, ) { self.text_highlights - .insert(Some(type_id), Arc::new((style, ranges))); + .insert(type_id, Arc::new((style, ranges))); } pub(crate) fn highlight_inlays( @@ -457,11 +457,11 @@ impl DisplayMap { } pub fn text_highlights(&self, type_id: TypeId) -> Option<(HighlightStyle, &[Range])> { - let highlights = self.text_highlights.get(&Some(type_id))?; + let highlights = self.text_highlights.get(&type_id)?; Some((highlights.0, &highlights.1)) } pub fn clear_highlights(&mut self, type_id: TypeId) -> bool { - let mut cleared = self.text_highlights.remove(&Some(type_id)).is_some(); + let mut cleared = self.text_highlights.remove(&type_id).is_some(); cleared |= self.inlay_highlights.remove(&type_id).is_some(); cleared } @@ -1239,7 +1239,7 @@ impl DisplaySnapshot { &self, ) -> Option>)>> { let type_id = TypeId::of::(); - self.text_highlights.get(&Some(type_id)).cloned() + self.text_highlights.get(&type_id).cloned() } #[allow(unused)] diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index 4598a5c015..e4884d3c43 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -211,7 +211,7 @@ pub struct InlayBufferRows<'a> { struct HighlightEndpoint { offset: InlayOffset, is_start: bool, - tag: Option, + tag: TypeId, style: HighlightStyle, } @@ -239,7 +239,7 @@ pub struct InlayChunks<'a> { max_output_offset: InlayOffset, highlight_styles: HighlightStyles, highlight_endpoints: Peekable>, - active_highlights: BTreeMap, HighlightStyle>, + active_highlights: BTreeMap, highlights: Highlights<'a>, snapshot: &'a InlaySnapshot, } @@ -1096,7 +1096,7 @@ impl InlaySnapshot { &self, cursor: &mut Cursor<'_, Transform, (InlayOffset, usize)>, range: &Range, - text_highlights: &TreeMap, Arc<(HighlightStyle, Vec>)>>, + text_highlights: &TreeMap>)>>, highlight_endpoints: &mut Vec, ) { while cursor.start().0 < range.end { @@ -1112,7 +1112,7 @@ impl InlaySnapshot { ))) }; - for (tag, text_highlights) in text_highlights.iter() { + for (&tag, text_highlights) in text_highlights.iter() { let style = text_highlights.0; let ranges = &text_highlights.1; @@ -1134,13 +1134,13 @@ impl InlaySnapshot { highlight_endpoints.push(HighlightEndpoint { offset: self.to_inlay_offset(range.start.to_offset(&self.buffer)), is_start: true, - tag: *tag, + tag, style, }); highlight_endpoints.push(HighlightEndpoint { offset: self.to_inlay_offset(range.end.to_offset(&self.buffer)), is_start: false, - tag: *tag, + tag, style, }); } @@ -1708,7 +1708,7 @@ mod tests { text_highlight_ranges.sort_by_key(|range| (range.start, Reverse(range.end))); log::info!("highlighting text ranges {text_highlight_ranges:?}"); text_highlights.insert( - Some(TypeId::of::<()>()), + TypeId::of::<()>(), Arc::new(( HighlightStyle::default(), text_highlight_ranges