Prepare for inlay and text highlight unification
This commit is contained in:
parent
4cc9f2f525
commit
420f8b7b15
5 changed files with 30 additions and 43 deletions
|
@ -5,7 +5,7 @@ mod tab_map;
|
||||||
mod wrap_map;
|
mod wrap_map;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
link_go_to_definition::InlayCoordinates, Anchor, AnchorRangeExt, InlayId, MultiBuffer,
|
link_go_to_definition::InlayRange, Anchor, AnchorRangeExt, InlayId, MultiBuffer,
|
||||||
MultiBufferSnapshot, ToOffset, ToPoint,
|
MultiBufferSnapshot, ToOffset, ToPoint,
|
||||||
};
|
};
|
||||||
pub use block_map::{BlockMap, BlockPoint};
|
pub use block_map::{BlockMap, BlockPoint};
|
||||||
|
@ -43,7 +43,7 @@ pub trait ToDisplayPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;
|
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 {
|
pub struct DisplayMap {
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
buffer: ModelHandle<MultiBuffer>,
|
||||||
|
@ -225,7 +225,7 @@ impl DisplayMap {
|
||||||
pub fn highlight_inlays(
|
pub fn highlight_inlays(
|
||||||
&mut self,
|
&mut self,
|
||||||
type_id: TypeId,
|
type_id: TypeId,
|
||||||
ranges: Vec<InlayCoordinates>,
|
ranges: Vec<InlayRange>,
|
||||||
style: HighlightStyle,
|
style: HighlightStyle,
|
||||||
) {
|
) {
|
||||||
self.inlay_highlights
|
self.inlay_highlights
|
||||||
|
@ -247,7 +247,7 @@ impl DisplayMap {
|
||||||
pub fn clear_inlay_highlights(
|
pub fn clear_inlay_highlights(
|
||||||
&mut self,
|
&mut self,
|
||||||
type_id: TypeId,
|
type_id: TypeId,
|
||||||
) -> Option<Arc<(HighlightStyle, Vec<InlayCoordinates>)>> {
|
) -> Option<Arc<(HighlightStyle, Vec<InlayRange>)>> {
|
||||||
self.inlay_highlights.remove(&Some(type_id))
|
self.inlay_highlights.remove(&Some(type_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1108,7 +1108,7 @@ impl InlaySnapshot {
|
||||||
&self,
|
&self,
|
||||||
inlay_highlights: &std::sync::Arc<(
|
inlay_highlights: &std::sync::Arc<(
|
||||||
HighlightStyle,
|
HighlightStyle,
|
||||||
Vec<crate::link_go_to_definition::InlayCoordinates>,
|
Vec<crate::link_go_to_definition::InlayRange>,
|
||||||
)>,
|
)>,
|
||||||
transform_start: Anchor,
|
transform_start: Anchor,
|
||||||
transform_end: Anchor,
|
transform_end: Anchor,
|
||||||
|
|
|
@ -65,7 +65,7 @@ use language::{
|
||||||
OffsetUtf16, Point, Selection, SelectionGoal, TransactionId,
|
OffsetUtf16, Point, Selection, SelectionGoal, TransactionId,
|
||||||
};
|
};
|
||||||
use link_go_to_definition::{
|
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 log::error;
|
||||||
use multi_buffer::ToOffsetUtf16;
|
use multi_buffer::ToOffsetUtf16;
|
||||||
|
@ -7720,7 +7720,7 @@ impl Editor {
|
||||||
|
|
||||||
pub fn highlight_inlays<T: 'static>(
|
pub fn highlight_inlays<T: 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
ranges: Vec<InlayCoordinates>,
|
ranges: Vec<InlayRange>,
|
||||||
style: HighlightStyle,
|
style: HighlightStyle,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
|
@ -7737,20 +7737,7 @@ impl Editor {
|
||||||
self.display_map.read(cx).text_highlights(TypeId::of::<T>())
|
self.display_map.read(cx).text_highlights(TypeId::of::<T>())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_text_highlights<T: 'static>(
|
pub fn clear_text_highlights<T: 'static>(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
&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>) {
|
|
||||||
let text_highlights = self
|
let text_highlights = self
|
||||||
.display_map
|
.display_map
|
||||||
.update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()));
|
.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.link_go_to_definition_state.task = None;
|
||||||
|
|
||||||
self.clear_highlights::<LinkGoToDefinitionState>(cx);
|
self.clear_text_highlights::<LinkGoToDefinitionState>(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
},
|
},
|
||||||
link_go_to_definition::{
|
link_go_to_definition::{
|
||||||
go_to_fetched_definition, go_to_fetched_type_definition, update_go_to_definition_link,
|
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,
|
mouse_context_menu, EditorSettings, EditorStyle, GutterHover, UnfoldAt,
|
||||||
};
|
};
|
||||||
|
@ -1929,7 +1929,7 @@ fn update_inlay_link_and_hover_points(
|
||||||
update_go_to_definition_link(
|
update_go_to_definition_link(
|
||||||
editor,
|
editor,
|
||||||
GoToDefinitionTrigger::InlayHint(
|
GoToDefinitionTrigger::InlayHint(
|
||||||
InlayCoordinates {
|
InlayRange {
|
||||||
inlay_position: hovered_hint.position,
|
inlay_position: hovered_hint.position,
|
||||||
highlight_start: part_range.start,
|
highlight_start: part_range.start,
|
||||||
highlight_end: part_range.end,
|
highlight_end: part_range.end,
|
||||||
|
|
|
@ -11,7 +11,7 @@ use util::TryFutureExt;
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
pub struct LinkGoToDefinitionState {
|
pub struct LinkGoToDefinitionState {
|
||||||
pub last_trigger_point: Option<TriggerPoint>,
|
pub last_trigger_point: Option<TriggerPoint>,
|
||||||
pub symbol_range: Option<SymbolRange>,
|
pub symbol_range: Option<DocumentRange>,
|
||||||
pub kind: Option<LinkDefinitionKind>,
|
pub kind: Option<LinkDefinitionKind>,
|
||||||
pub definitions: Vec<LocationLink>,
|
pub definitions: Vec<LocationLink>,
|
||||||
pub task: Option<Task<Option<()>>>,
|
pub task: Option<Task<Option<()>>>,
|
||||||
|
@ -19,12 +19,12 @@ pub struct LinkGoToDefinitionState {
|
||||||
|
|
||||||
pub enum GoToDefinitionTrigger {
|
pub enum GoToDefinitionTrigger {
|
||||||
Text(DisplayPoint),
|
Text(DisplayPoint),
|
||||||
InlayHint(InlayCoordinates, LocationLink),
|
InlayHint(InlayRange, LocationLink),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct InlayCoordinates {
|
pub struct InlayRange {
|
||||||
pub inlay_position: Anchor,
|
pub inlay_position: Anchor,
|
||||||
pub highlight_start: InlayOffset,
|
pub highlight_start: InlayOffset,
|
||||||
pub highlight_end: InlayOffset,
|
pub highlight_end: InlayOffset,
|
||||||
|
@ -33,28 +33,28 @@ pub struct InlayCoordinates {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum TriggerPoint {
|
pub enum TriggerPoint {
|
||||||
Text(Anchor),
|
Text(Anchor),
|
||||||
InlayHint(InlayCoordinates, LocationLink),
|
InlayHint(InlayRange, LocationLink),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum SymbolRange {
|
pub enum DocumentRange {
|
||||||
Text(Range<Anchor>),
|
Text(Range<Anchor>),
|
||||||
Inlay(InlayCoordinates),
|
Inlay(InlayRange),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SymbolRange {
|
impl DocumentRange {
|
||||||
fn point_within_range(&self, trigger_point: &TriggerPoint, snapshot: &EditorSnapshot) -> bool {
|
fn point_within_range(&self, trigger_point: &TriggerPoint, snapshot: &EditorSnapshot) -> bool {
|
||||||
match (self, trigger_point) {
|
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();
|
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()
|
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_start.cmp(&point.highlight_end).is_le()
|
||||||
&& range.highlight_end.cmp(&point.highlight_end).is_ge()
|
&& range.highlight_end.cmp(&point.highlight_end).is_ge()
|
||||||
}
|
}
|
||||||
(SymbolRange::Inlay(_), TriggerPoint::Text(_))
|
(DocumentRange::Inlay(_), TriggerPoint::Text(_))
|
||||||
| (SymbolRange::Text(_), TriggerPoint::InlayHint(_, _)) => false,
|
| (DocumentRange::Text(_), TriggerPoint::InlayHint(_, _)) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ pub fn show_link_definition(
|
||||||
.buffer_snapshot
|
.buffer_snapshot
|
||||||
.anchor_in_excerpt(excerpt_id.clone(), origin.range.end);
|
.anchor_in_excerpt(excerpt_id.clone(), origin.range.end);
|
||||||
|
|
||||||
SymbolRange::Text(start..end)
|
DocumentRange::Text(start..end)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
definition_result,
|
definition_result,
|
||||||
|
@ -226,14 +226,14 @@ pub fn show_link_definition(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
TriggerPoint::InlayHint(trigger_source, trigger_target) => Some((
|
TriggerPoint::InlayHint(trigger_source, trigger_target) => Some((
|
||||||
Some(SymbolRange::Inlay(trigger_source.clone())),
|
Some(DocumentRange::Inlay(trigger_source.clone())),
|
||||||
vec![trigger_target.clone()],
|
vec![trigger_target.clone()],
|
||||||
)),
|
)),
|
||||||
};
|
};
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
// Clear any existing highlights
|
// 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.kind = Some(definition_kind);
|
||||||
this.link_go_to_definition_state.symbol_range = result
|
this.link_go_to_definition_state.symbol_range = result
|
||||||
.as_ref()
|
.as_ref()
|
||||||
|
@ -276,24 +276,24 @@ pub fn show_link_definition(
|
||||||
let snapshot = &snapshot.buffer_snapshot;
|
let snapshot = &snapshot.buffer_snapshot;
|
||||||
// If no symbol range returned from language server, use the surrounding word.
|
// If no symbol range returned from language server, use the surrounding word.
|
||||||
let (offset_range, _) = snapshot.surrounding_word(trigger_anchor);
|
let (offset_range, _) = snapshot.surrounding_word(trigger_anchor);
|
||||||
SymbolRange::Text(
|
DocumentRange::Text(
|
||||||
snapshot.anchor_before(offset_range.start)
|
snapshot.anchor_before(offset_range.start)
|
||||||
..snapshot.anchor_after(offset_range.end),
|
..snapshot.anchor_after(offset_range.end),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
TriggerPoint::InlayHint(inlay_coordinates, _) => {
|
TriggerPoint::InlayHint(inlay_coordinates, _) => {
|
||||||
SymbolRange::Inlay(inlay_coordinates)
|
DocumentRange::Inlay(inlay_coordinates)
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
match highlight_range {
|
match highlight_range {
|
||||||
SymbolRange::Text(text_range) => this
|
DocumentRange::Text(text_range) => this
|
||||||
.highlight_text::<LinkGoToDefinitionState>(
|
.highlight_text::<LinkGoToDefinitionState>(
|
||||||
vec![text_range],
|
vec![text_range],
|
||||||
style,
|
style,
|
||||||
cx,
|
cx,
|
||||||
),
|
),
|
||||||
SymbolRange::Inlay(inlay_coordinates) => this
|
DocumentRange::Inlay(inlay_coordinates) => this
|
||||||
.highlight_inlays::<LinkGoToDefinitionState>(
|
.highlight_inlays::<LinkGoToDefinitionState>(
|
||||||
vec![inlay_coordinates],
|
vec![inlay_coordinates],
|
||||||
style,
|
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.link_go_to_definition_state.task = None;
|
||||||
|
|
||||||
editor.clear_highlights::<LinkGoToDefinitionState>(cx);
|
editor.clear_text_highlights::<LinkGoToDefinitionState>(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn go_to_fetched_definition(
|
pub fn go_to_fetched_definition(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue