Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Prepare for inlay and text highlight unification
Kirill Bulatov420f8b7b1597
diff --git a/crates/editor/src/display_map.rs b/crates/editor/src/display_map.rsindex 9df2919351d..4f08be73b94 100644--- a/crates/editor/src/display_map.rs+++ b/crates/editor/src/display_map.rs@@ -5,7 +5,7 @@ mod tab_map;mod wrap_map;use crate::{- link_go_to_definition::InlayCoordinates, Anchor, AnchorRangeExt, InlayId, MultiBuffer,+ link_go_to_definition::InlayRange, Anchor, AnchorRangeExt, InlayId, MultiBuffer,MultiBufferSnapshot, ToOffset, ToPoint,};pub use block_map::{BlockMap, BlockPoint};@@ -43,7 +43,7 @@ pub trait ToDisplayPoint {}type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;-type InlayHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<InlayCoordinates>)>>;+type InlayHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<InlayRange>)>>;pub struct DisplayMap {buffer: ModelHandle<MultiBuffer>,@@ -225,7 +225,7 @@ impl DisplayMap {pub fn highlight_inlays(&mut self,type_id: TypeId,- ranges: Vec<InlayCoordinates>,+ ranges: Vec<InlayRange>,style: HighlightStyle,) {self.inlay_highlights@@ -247,7 +247,7 @@ impl DisplayMap {pub fn clear_inlay_highlights(&mut self,type_id: TypeId,- ) -> Option<Arc<(HighlightStyle, Vec<InlayCoordinates>)>> {+ ) -> Option<Arc<(HighlightStyle, Vec<InlayRange>)>> {self.inlay_highlights.remove(&Some(type_id))}diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rsindex 19b3ec79242..cc730f93332 100644--- a/crates/editor/src/display_map/inlay_map.rs+++ b/crates/editor/src/display_map/inlay_map.rs@@ -1108,7 +1108,7 @@ impl InlaySnapshot {&self,inlay_highlights: &std::sync::Arc<(HighlightStyle,- Vec<crate::link_go_to_definition::InlayCoordinates>,+ Vec<crate::link_go_to_definition::InlayRange>,)>,transform_start: Anchor,transform_end: Anchor,diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rsindex 6c5d1a45ac0..af352d2649e 100644--- a/crates/editor/src/editor.rs+++ b/crates/editor/src/editor.rs@@ -65,7 +65,7 @@ use language::{OffsetUtf16, Point, Selection, SelectionGoal, TransactionId,};use link_go_to_definition::{- hide_link_definition, show_link_definition, InlayCoordinates, LinkGoToDefinitionState,+ hide_link_definition, show_link_definition, InlayRange, LinkGoToDefinitionState,};use log::error;use multi_buffer::ToOffsetUtf16;@@ -7720,7 +7720,7 @@ impl Editor {pub fn highlight_inlays<T: 'static>(&mut self,- ranges: Vec<InlayCoordinates>,+ ranges: Vec<InlayRange>,style: HighlightStyle,cx: &mut ViewContext<Self>,) {@@ -7737,20 +7737,7 @@ impl Editor {self.display_map.read(cx).text_highlights(TypeId::of::<T>())}- pub fn clear_text_highlights<T: 'static>(- &mut self,- cx: &mut ViewContext<Self>,- ) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {- let highlights = self- .display_map- .update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()));- if highlights.is_some() {- cx.notify();- }- highlights- }-- pub fn clear_highlights<T: 'static>(&mut self, cx: &mut ViewContext<Self>) {+ pub fn clear_text_highlights<T: 'static>(&mut self, cx: &mut ViewContext<Self>) {let text_highlights = self.display_map.update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()));@@ -8353,7 +8340,7 @@ impl View for Editor {self.link_go_to_definition_state.task = None;- self.clear_highlights::<LinkGoToDefinitionState>(cx);+ self.clear_text_highlights::<LinkGoToDefinitionState>(cx);}falsediff --git a/crates/editor/src/element.rs b/crates/editor/src/element.rsindex 10809d89629..2be5105b334 100644--- a/crates/editor/src/element.rs+++ b/crates/editor/src/element.rs@@ -13,7 +13,7 @@ use crate::{},link_go_to_definition::{go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link,- GoToDefinitionTrigger, InlayCoordinates,+ GoToDefinitionTrigger, InlayRange,},mouse_context_menu, EditorSettings, EditorStyle, GutterHover, UnfoldAt,};@@ -1929,7 +1929,7 @@ fn update_inlay_link_and_hover_points(update_go_to_definition_link(editor,GoToDefinitionTrigger::InlayHint(- InlayCoordinates {+ InlayRange {inlay_position: hovered_hint.position,highlight_start: part_range.start,highlight_end: part_range.end,diff --git a/crates/editor/src/link_go_to_definition.rs b/crates/editor/src/link_go_to_definition.rsindex ee2b5360426..5bc45720a2b 100644--- a/crates/editor/src/link_go_to_definition.rs+++ b/crates/editor/src/link_go_to_definition.rs@@ -11,7 +11,7 @@ use util::TryFutureExt;#[derive(Debug, Default)]pub struct LinkGoToDefinitionState {pub last_trigger_point: Option<TriggerPoint>,- pub symbol_range: Option<SymbolRange>,+ pub symbol_range: Option<DocumentRange>,pub kind: Option<LinkDefinitionKind>,pub definitions: Vec<LocationLink>,pub task: Option<Task<Option<()>>>,@@ -19,12 +19,12 @@ pub struct LinkGoToDefinitionState {pub enum GoToDefinitionTrigger {Text(DisplayPoint),- InlayHint(InlayCoordinates, LocationLink),+ InlayHint(InlayRange, LocationLink),None,}#[derive(Debug, Clone, Copy)]-pub struct InlayCoordinates {+pub struct InlayRange {pub inlay_position: Anchor,pub highlight_start: InlayOffset,pub highlight_end: InlayOffset,@@ -33,28 +33,28 @@ pub struct InlayCoordinates {#[derive(Debug, Clone)]pub enum TriggerPoint {Text(Anchor),- InlayHint(InlayCoordinates, LocationLink),+ InlayHint(InlayRange, LocationLink),}#[derive(Debug, Clone)]-pub enum SymbolRange {+pub enum DocumentRange {Text(Range<Anchor>),- Inlay(InlayCoordinates),+ Inlay(InlayRange),}-impl SymbolRange {+impl DocumentRange {fn point_within_range(&self, trigger_point: &TriggerPoint, snapshot: &EditorSnapshot) -> bool {match (self, trigger_point) {- (SymbolRange::Text(range), TriggerPoint::Text(point)) => {+ (DocumentRange::Text(range), TriggerPoint::Text(point)) => {let point_after_start = range.start.cmp(point, &snapshot.buffer_snapshot).is_le();point_after_start && range.end.cmp(point, &snapshot.buffer_snapshot).is_ge()}- (SymbolRange::Inlay(range), TriggerPoint::InlayHint(point, _)) => {+ (DocumentRange::Inlay(range), TriggerPoint::InlayHint(point, _)) => {range.highlight_start.cmp(&point.highlight_end).is_le()&& range.highlight_end.cmp(&point.highlight_end).is_ge()}- (SymbolRange::Inlay(_), TriggerPoint::Text(_))- | (SymbolRange::Text(_), TriggerPoint::InlayHint(_, _)) => false,+ (DocumentRange::Inlay(_), TriggerPoint::Text(_))+ | (DocumentRange::Text(_), TriggerPoint::InlayHint(_, _)) => false,}}}@@ -218,7 +218,7 @@ pub fn show_link_definition(.buffer_snapshot.anchor_in_excerpt(excerpt_id.clone(), origin.range.end);- SymbolRange::Text(start..end)+ DocumentRange::Text(start..end)})}),definition_result,@@ -226,14 +226,14 @@ pub fn show_link_definition(})}TriggerPoint::InlayHint(trigger_source, trigger_target) => Some((- Some(SymbolRange::Inlay(trigger_source.clone())),+ Some(DocumentRange::Inlay(trigger_source.clone())),vec![trigger_target.clone()],)),};this.update(&mut cx, |this, cx| {// Clear any existing highlights- this.clear_highlights::<LinkGoToDefinitionState>(cx);+ this.clear_text_highlights::<LinkGoToDefinitionState>(cx);this.link_go_to_definition_state.kind = Some(definition_kind);this.link_go_to_definition_state.symbol_range = result.as_ref()@@ -276,24 +276,24 @@ pub fn show_link_definition(let snapshot = &snapshot.buffer_snapshot;// If no symbol range returned from language server, use the surrounding word.let (offset_range, _) = snapshot.surrounding_word(trigger_anchor);- SymbolRange::Text(+ DocumentRange::Text(snapshot.anchor_before(offset_range.start)..snapshot.anchor_after(offset_range.end),)}TriggerPoint::InlayHint(inlay_coordinates, _) => {- SymbolRange::Inlay(inlay_coordinates)+ DocumentRange::Inlay(inlay_coordinates)}});match highlight_range {- SymbolRange::Text(text_range) => this+ DocumentRange::Text(text_range) => this.highlight_text::<LinkGoToDefinitionState>(vec![text_range],style,cx,),- SymbolRange::Inlay(inlay_coordinates) => this+ DocumentRange::Inlay(inlay_coordinates) => this.highlight_inlays::<LinkGoToDefinitionState>(vec![inlay_coordinates],style,@@ -325,7 +325,7 @@ pub fn hide_link_definition(editor: &mut Editor, cx: &mut ViewContext<Editor>) {editor.link_go_to_definition_state.task = None;- editor.clear_highlights::<LinkGoToDefinitionState>(cx);+ editor.clear_text_highlights::<LinkGoToDefinitionState>(cx);}pub fn go_to_fetched_definition(