Compare commits
16 commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
75575c1561 | ||
![]() |
f97a2441ec | ||
![]() |
1dfcb81cf5 | ||
![]() |
17b6eb91b3 | ||
![]() |
1d41686013 | ||
![]() |
263afc4d59 | ||
![]() |
f2f9db73f8 | ||
![]() |
62e07bb162 | ||
![]() |
ee1a9d81f6 | ||
![]() |
fad708a691 | ||
![]() |
950183b853 | ||
![]() |
d6453ecc64 | ||
![]() |
b88adde7f1 | ||
![]() |
1e4878e20f | ||
![]() |
522937b5f0 | ||
![]() |
787336613c |
31 changed files with 745 additions and 622 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -9794,7 +9794,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "zed"
|
name = "zed"
|
||||||
version = "0.104.0"
|
version = "0.104.4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"activity_indicator",
|
"activity_indicator",
|
||||||
"ai",
|
"ai",
|
||||||
|
|
|
@ -125,6 +125,8 @@
|
||||||
"g shift-t": "pane::ActivatePrevItem",
|
"g shift-t": "pane::ActivatePrevItem",
|
||||||
"g d": "editor::GoToDefinition",
|
"g d": "editor::GoToDefinition",
|
||||||
"g shift-d": "editor::GoToTypeDefinition",
|
"g shift-d": "editor::GoToTypeDefinition",
|
||||||
|
"g s": "outline::Toggle",
|
||||||
|
"g shift-s": "project_symbols::Toggle",
|
||||||
"g .": "editor::ToggleCodeActions", // zed specific
|
"g .": "editor::ToggleCodeActions", // zed specific
|
||||||
"g shift-a": "editor::FindAllReferences", // zed specific
|
"g shift-a": "editor::FindAllReferences", // zed specific
|
||||||
"g *": [
|
"g *": [
|
||||||
|
|
|
@ -386,10 +386,12 @@ impl AssistantPanel {
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.finish_inline_assist(inline_assist_id, false, cx);
|
this.finish_inline_assist(inline_assist_id, false, cx);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.finish_inline_assist(inline_assist_id, false, cx);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
@ -702,7 +704,7 @@ impl AssistantPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
if foreground_ranges.is_empty() {
|
if foreground_ranges.is_empty() {
|
||||||
editor.clear_text_highlights::<PendingInlineAssist>(cx);
|
editor.clear_highlights::<PendingInlineAssist>(cx);
|
||||||
} else {
|
} else {
|
||||||
editor.highlight_text::<PendingInlineAssist>(
|
editor.highlight_text::<PendingInlineAssist>(
|
||||||
foreground_ranges,
|
foreground_ranges,
|
||||||
|
@ -2837,6 +2839,7 @@ impl InlineAssistant {
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
self.confirmed = false;
|
||||||
editor.set_read_only(false);
|
editor.set_read_only(false);
|
||||||
editor.set_field_editor_style(
|
editor.set_field_editor_style(
|
||||||
Some(Arc::new(|theme| theme.assistant.inline.editor.clone())),
|
Some(Arc::new(|theme| theme.assistant.inline.editor.clone())),
|
||||||
|
|
|
@ -5,11 +5,11 @@ mod tab_map;
|
||||||
mod wrap_map;
|
mod wrap_map;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
link_go_to_definition::{DocumentRange, InlayRange},
|
link_go_to_definition::InlayHighlight, Anchor, AnchorRangeExt, InlayId, MultiBuffer,
|
||||||
Anchor, AnchorRangeExt, InlayId, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint,
|
MultiBufferSnapshot, ToOffset, ToPoint,
|
||||||
};
|
};
|
||||||
pub use block_map::{BlockMap, BlockPoint};
|
pub use block_map::{BlockMap, BlockPoint};
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{BTreeMap, HashMap, HashSet};
|
||||||
use fold_map::FoldMap;
|
use fold_map::FoldMap;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
color::Color,
|
color::Color,
|
||||||
|
@ -43,7 +43,8 @@ pub trait ToDisplayPoint {
|
||||||
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint;
|
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<DocumentRange>)>>;
|
type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;
|
||||||
|
type InlayHighlights = BTreeMap<TypeId, HashMap<InlayId, (HighlightStyle, InlayHighlight)>>;
|
||||||
|
|
||||||
pub struct DisplayMap {
|
pub struct DisplayMap {
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
buffer: ModelHandle<MultiBuffer>,
|
||||||
|
@ -54,6 +55,7 @@ pub struct DisplayMap {
|
||||||
wrap_map: ModelHandle<WrapMap>,
|
wrap_map: ModelHandle<WrapMap>,
|
||||||
block_map: BlockMap,
|
block_map: BlockMap,
|
||||||
text_highlights: TextHighlights,
|
text_highlights: TextHighlights,
|
||||||
|
inlay_highlights: InlayHighlights,
|
||||||
pub clip_at_line_ends: bool,
|
pub clip_at_line_ends: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +91,7 @@ impl DisplayMap {
|
||||||
wrap_map,
|
wrap_map,
|
||||||
block_map,
|
block_map,
|
||||||
text_highlights: Default::default(),
|
text_highlights: Default::default(),
|
||||||
|
inlay_highlights: Default::default(),
|
||||||
clip_at_line_ends: false,
|
clip_at_line_ends: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,6 +116,7 @@ impl DisplayMap {
|
||||||
wrap_snapshot,
|
wrap_snapshot,
|
||||||
block_snapshot,
|
block_snapshot,
|
||||||
text_highlights: self.text_highlights.clone(),
|
text_highlights: self.text_highlights.clone(),
|
||||||
|
inlay_highlights: self.inlay_highlights.clone(),
|
||||||
clip_at_line_ends: self.clip_at_line_ends,
|
clip_at_line_ends: self.clip_at_line_ends,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -215,37 +219,32 @@ impl DisplayMap {
|
||||||
ranges: Vec<Range<Anchor>>,
|
ranges: Vec<Range<Anchor>>,
|
||||||
style: HighlightStyle,
|
style: HighlightStyle,
|
||||||
) {
|
) {
|
||||||
self.text_highlights.insert(
|
self.text_highlights
|
||||||
Some(type_id),
|
.insert(Some(type_id), Arc::new((style, ranges)));
|
||||||
Arc::new((style, ranges.into_iter().map(DocumentRange::Text).collect())),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn highlight_inlays(
|
pub fn highlight_inlays(
|
||||||
&mut self,
|
&mut self,
|
||||||
type_id: TypeId,
|
type_id: TypeId,
|
||||||
ranges: Vec<InlayRange>,
|
highlights: Vec<InlayHighlight>,
|
||||||
style: HighlightStyle,
|
style: HighlightStyle,
|
||||||
) {
|
) {
|
||||||
self.text_highlights.insert(
|
for highlight in highlights {
|
||||||
Some(type_id),
|
self.inlay_highlights
|
||||||
Arc::new((
|
.entry(type_id)
|
||||||
style,
|
.or_default()
|
||||||
ranges.into_iter().map(DocumentRange::Inlay).collect(),
|
.insert(highlight.inlay, (style, highlight));
|
||||||
)),
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_highlights(&self, type_id: TypeId) -> Option<(HighlightStyle, &[DocumentRange])> {
|
pub fn text_highlights(&self, type_id: TypeId) -> Option<(HighlightStyle, &[Range<Anchor>])> {
|
||||||
let highlights = self.text_highlights.get(&Some(type_id))?;
|
let highlights = self.text_highlights.get(&Some(type_id))?;
|
||||||
Some((highlights.0, &highlights.1))
|
Some((highlights.0, &highlights.1))
|
||||||
}
|
}
|
||||||
|
pub fn clear_highlights(&mut self, type_id: TypeId) -> bool {
|
||||||
pub fn clear_text_highlights(
|
let mut cleared = self.text_highlights.remove(&Some(type_id)).is_some();
|
||||||
&mut self,
|
cleared |= self.inlay_highlights.remove(&type_id).is_none();
|
||||||
type_id: TypeId,
|
cleared
|
||||||
) -> Option<Arc<(HighlightStyle, Vec<DocumentRange>)>> {
|
|
||||||
self.text_highlights.remove(&Some(type_id))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_font(&self, font_id: FontId, font_size: f32, cx: &mut ModelContext<Self>) -> bool {
|
pub fn set_font(&self, font_id: FontId, font_size: f32, cx: &mut ModelContext<Self>) -> bool {
|
||||||
|
@ -309,6 +308,14 @@ impl DisplayMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Default)]
|
||||||
|
pub struct Highlights<'a> {
|
||||||
|
pub text_highlights: Option<&'a TextHighlights>,
|
||||||
|
pub inlay_highlights: Option<&'a InlayHighlights>,
|
||||||
|
pub inlay_highlight_style: Option<HighlightStyle>,
|
||||||
|
pub suggestion_highlight_style: Option<HighlightStyle>,
|
||||||
|
}
|
||||||
|
|
||||||
pub struct DisplaySnapshot {
|
pub struct DisplaySnapshot {
|
||||||
pub buffer_snapshot: MultiBufferSnapshot,
|
pub buffer_snapshot: MultiBufferSnapshot,
|
||||||
pub fold_snapshot: fold_map::FoldSnapshot,
|
pub fold_snapshot: fold_map::FoldSnapshot,
|
||||||
|
@ -317,6 +324,7 @@ pub struct DisplaySnapshot {
|
||||||
wrap_snapshot: wrap_map::WrapSnapshot,
|
wrap_snapshot: wrap_map::WrapSnapshot,
|
||||||
block_snapshot: block_map::BlockSnapshot,
|
block_snapshot: block_map::BlockSnapshot,
|
||||||
text_highlights: TextHighlights,
|
text_highlights: TextHighlights,
|
||||||
|
inlay_highlights: InlayHighlights,
|
||||||
clip_at_line_ends: bool,
|
clip_at_line_ends: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,15 +430,6 @@ impl DisplaySnapshot {
|
||||||
.to_inlay_offset(anchor.to_offset(&self.buffer_snapshot))
|
.to_inlay_offset(anchor.to_offset(&self.buffer_snapshot))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn inlay_offset_to_display_point(&self, offset: InlayOffset, bias: Bias) -> DisplayPoint {
|
|
||||||
let inlay_point = self.inlay_snapshot.to_point(offset);
|
|
||||||
let fold_point = self.fold_snapshot.to_fold_point(inlay_point, bias);
|
|
||||||
let tab_point = self.tab_snapshot.to_tab_point(fold_point);
|
|
||||||
let wrap_point = self.wrap_snapshot.tab_point_to_wrap_point(tab_point);
|
|
||||||
let block_point = self.block_snapshot.to_block_point(wrap_point);
|
|
||||||
DisplayPoint(block_point)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn display_point_to_inlay_point(&self, point: DisplayPoint, bias: Bias) -> InlayPoint {
|
fn display_point_to_inlay_point(&self, point: DisplayPoint, bias: Bias) -> InlayPoint {
|
||||||
let block_point = point.0;
|
let block_point = point.0;
|
||||||
let wrap_point = self.block_snapshot.to_wrap_point(block_point);
|
let wrap_point = self.block_snapshot.to_wrap_point(block_point);
|
||||||
|
@ -463,9 +462,7 @@ impl DisplaySnapshot {
|
||||||
.chunks(
|
.chunks(
|
||||||
display_row..self.max_point().row() + 1,
|
display_row..self.max_point().row() + 1,
|
||||||
false,
|
false,
|
||||||
None,
|
Highlights::default(),
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.map(|h| h.text)
|
.map(|h| h.text)
|
||||||
}
|
}
|
||||||
|
@ -474,7 +471,7 @@ impl DisplaySnapshot {
|
||||||
pub fn reverse_text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> {
|
pub fn reverse_text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> {
|
||||||
(0..=display_row).into_iter().rev().flat_map(|row| {
|
(0..=display_row).into_iter().rev().flat_map(|row| {
|
||||||
self.block_snapshot
|
self.block_snapshot
|
||||||
.chunks(row..row + 1, false, None, None, None)
|
.chunks(row..row + 1, false, Highlights::default())
|
||||||
.map(|h| h.text)
|
.map(|h| h.text)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -482,19 +479,22 @@ impl DisplaySnapshot {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chunks(
|
pub fn chunks<'a>(
|
||||||
&self,
|
&'a self,
|
||||||
display_rows: Range<u32>,
|
display_rows: Range<u32>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
hint_highlight_style: Option<HighlightStyle>,
|
inlay_highlight_style: Option<HighlightStyle>,
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
suggestion_highlight_style: Option<HighlightStyle>,
|
||||||
) -> DisplayChunks<'_> {
|
) -> DisplayChunks<'_> {
|
||||||
self.block_snapshot.chunks(
|
self.block_snapshot.chunks(
|
||||||
display_rows,
|
display_rows,
|
||||||
language_aware,
|
language_aware,
|
||||||
Some(&self.text_highlights),
|
Highlights {
|
||||||
hint_highlight_style,
|
text_highlights: Some(&self.text_highlights),
|
||||||
suggestion_highlight_style,
|
inlay_highlights: Some(&self.inlay_highlights),
|
||||||
|
inlay_highlight_style,
|
||||||
|
suggestion_highlight_style,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -752,12 +752,20 @@ impl DisplaySnapshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn highlight_ranges<Tag: ?Sized + 'static>(
|
pub fn text_highlight_ranges<Tag: ?Sized + 'static>(
|
||||||
&self,
|
&self,
|
||||||
) -> Option<Arc<(HighlightStyle, Vec<DocumentRange>)>> {
|
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
|
||||||
let type_id = TypeId::of::<Tag>();
|
let type_id = TypeId::of::<Tag>();
|
||||||
self.text_highlights.get(&Some(type_id)).cloned()
|
self.text_highlights.get(&Some(type_id)).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
|
pub fn inlay_highlights<Tag: ?Sized + 'static>(
|
||||||
|
&self,
|
||||||
|
) -> Option<&HashMap<InlayId, (HighlightStyle, InlayHighlight)>> {
|
||||||
|
let type_id = TypeId::of::<Tag>();
|
||||||
|
self.inlay_highlights.get(&type_id)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Default, Eq, Ord, PartialOrd, PartialEq)]
|
#[derive(Copy, Clone, Default, Eq, Ord, PartialOrd, PartialEq)]
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
use super::{
|
use super::{
|
||||||
wrap_map::{self, WrapEdit, WrapPoint, WrapSnapshot},
|
wrap_map::{self, WrapEdit, WrapPoint, WrapSnapshot},
|
||||||
TextHighlights,
|
Highlights,
|
||||||
};
|
};
|
||||||
use crate::{Anchor, Editor, ExcerptId, ExcerptRange, ToPoint as _};
|
use crate::{Anchor, Editor, ExcerptId, ExcerptRange, ToPoint as _};
|
||||||
use collections::{Bound, HashMap, HashSet};
|
use collections::{Bound, HashMap, HashSet};
|
||||||
use gpui::{fonts::HighlightStyle, AnyElement, ViewContext};
|
use gpui::{AnyElement, ViewContext};
|
||||||
use language::{BufferSnapshot, Chunk, Patch, Point};
|
use language::{BufferSnapshot, Chunk, Patch, Point};
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use std::{
|
use std::{
|
||||||
|
@ -576,9 +576,7 @@ impl BlockSnapshot {
|
||||||
self.chunks(
|
self.chunks(
|
||||||
0..self.transforms.summary().output_rows,
|
0..self.transforms.summary().output_rows,
|
||||||
false,
|
false,
|
||||||
None,
|
Highlights::default(),
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.map(|chunk| chunk.text)
|
.map(|chunk| chunk.text)
|
||||||
.collect()
|
.collect()
|
||||||
|
@ -588,9 +586,7 @@ impl BlockSnapshot {
|
||||||
&'a self,
|
&'a self,
|
||||||
rows: Range<u32>,
|
rows: Range<u32>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
highlights: Highlights<'a>,
|
||||||
hint_highlight_style: Option<HighlightStyle>,
|
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
|
||||||
) -> BlockChunks<'a> {
|
) -> BlockChunks<'a> {
|
||||||
let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows);
|
let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows);
|
||||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
|
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
|
||||||
|
@ -622,9 +618,7 @@ impl BlockSnapshot {
|
||||||
input_chunks: self.wrap_snapshot.chunks(
|
input_chunks: self.wrap_snapshot.chunks(
|
||||||
input_start..input_end,
|
input_start..input_end,
|
||||||
language_aware,
|
language_aware,
|
||||||
text_highlights,
|
highlights,
|
||||||
hint_highlight_style,
|
|
||||||
suggestion_highlight_style,
|
|
||||||
),
|
),
|
||||||
input_chunk: Default::default(),
|
input_chunk: Default::default(),
|
||||||
transforms: cursor,
|
transforms: cursor,
|
||||||
|
@ -1501,9 +1495,7 @@ mod tests {
|
||||||
.chunks(
|
.chunks(
|
||||||
start_row as u32..blocks_snapshot.max_point().row + 1,
|
start_row as u32..blocks_snapshot.max_point().row + 1,
|
||||||
false,
|
false,
|
||||||
None,
|
Highlights::default(),
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.map(|chunk| chunk.text)
|
.map(|chunk| chunk.text)
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::{
|
use super::{
|
||||||
inlay_map::{InlayBufferRows, InlayChunks, InlayEdit, InlayOffset, InlayPoint, InlaySnapshot},
|
inlay_map::{InlayBufferRows, InlayChunks, InlayEdit, InlayOffset, InlayPoint, InlaySnapshot},
|
||||||
TextHighlights,
|
Highlights,
|
||||||
};
|
};
|
||||||
use crate::{Anchor, AnchorRangeExt, MultiBufferSnapshot, ToOffset};
|
use crate::{Anchor, AnchorRangeExt, MultiBufferSnapshot, ToOffset};
|
||||||
use gpui::{color::Color, fonts::HighlightStyle};
|
use gpui::{color::Color, fonts::HighlightStyle};
|
||||||
|
@ -475,7 +475,7 @@ pub struct FoldSnapshot {
|
||||||
impl FoldSnapshot {
|
impl FoldSnapshot {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn text(&self) -> String {
|
pub fn text(&self) -> String {
|
||||||
self.chunks(FoldOffset(0)..self.len(), false, None, None, None)
|
self.chunks(FoldOffset(0)..self.len(), false, Highlights::default())
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -651,9 +651,7 @@ impl FoldSnapshot {
|
||||||
&'a self,
|
&'a self,
|
||||||
range: Range<FoldOffset>,
|
range: Range<FoldOffset>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
highlights: Highlights<'a>,
|
||||||
hint_highlight_style: Option<HighlightStyle>,
|
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
|
||||||
) -> FoldChunks<'a> {
|
) -> FoldChunks<'a> {
|
||||||
let mut transform_cursor = self.transforms.cursor::<(FoldOffset, InlayOffset)>();
|
let mut transform_cursor = self.transforms.cursor::<(FoldOffset, InlayOffset)>();
|
||||||
|
|
||||||
|
@ -674,9 +672,7 @@ impl FoldSnapshot {
|
||||||
inlay_chunks: self.inlay_snapshot.chunks(
|
inlay_chunks: self.inlay_snapshot.chunks(
|
||||||
inlay_start..inlay_end,
|
inlay_start..inlay_end,
|
||||||
language_aware,
|
language_aware,
|
||||||
text_highlights,
|
highlights,
|
||||||
hint_highlight_style,
|
|
||||||
suggestion_highlight_style,
|
|
||||||
),
|
),
|
||||||
inlay_chunk: None,
|
inlay_chunk: None,
|
||||||
inlay_offset: inlay_start,
|
inlay_offset: inlay_start,
|
||||||
|
@ -687,8 +683,12 @@ impl FoldSnapshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn chars_at(&self, start: FoldPoint) -> impl '_ + Iterator<Item = char> {
|
pub fn chars_at(&self, start: FoldPoint) -> impl '_ + Iterator<Item = char> {
|
||||||
self.chunks(start.to_offset(self)..self.len(), false, None, None, None)
|
self.chunks(
|
||||||
.flat_map(|chunk| chunk.text.chars())
|
start.to_offset(self)..self.len(),
|
||||||
|
false,
|
||||||
|
Highlights::default(),
|
||||||
|
)
|
||||||
|
.flat_map(|chunk| chunk.text.chars())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -1496,7 +1496,7 @@ mod tests {
|
||||||
let text = &expected_text[start.0..end.0];
|
let text = &expected_text[start.0..end.0];
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
snapshot
|
snapshot
|
||||||
.chunks(start..end, false, None, None, None)
|
.chunks(start..end, false, Highlights::default())
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
text,
|
text,
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
link_go_to_definition::DocumentRange,
|
|
||||||
multi_buffer::{MultiBufferChunks, MultiBufferRows},
|
multi_buffer::{MultiBufferChunks, MultiBufferRows},
|
||||||
Anchor, InlayId, MultiBufferSnapshot, ToOffset,
|
Anchor, InlayId, MultiBufferSnapshot, ToOffset,
|
||||||
};
|
};
|
||||||
|
@ -11,12 +10,13 @@ use std::{
|
||||||
cmp,
|
cmp,
|
||||||
iter::Peekable,
|
iter::Peekable,
|
||||||
ops::{Add, AddAssign, Range, Sub, SubAssign},
|
ops::{Add, AddAssign, Range, Sub, SubAssign},
|
||||||
|
sync::Arc,
|
||||||
vec,
|
vec,
|
||||||
};
|
};
|
||||||
use sum_tree::{Bias, Cursor, SumTree};
|
use sum_tree::{Bias, Cursor, SumTree, TreeMap};
|
||||||
use text::{Patch, Rope};
|
use text::{Patch, Rope};
|
||||||
|
|
||||||
use super::TextHighlights;
|
use super::Highlights;
|
||||||
|
|
||||||
pub struct InlayMap {
|
pub struct InlayMap {
|
||||||
snapshot: InlaySnapshot,
|
snapshot: InlaySnapshot,
|
||||||
|
@ -214,10 +214,11 @@ pub struct InlayChunks<'a> {
|
||||||
inlay_chunk: Option<&'a str>,
|
inlay_chunk: Option<&'a str>,
|
||||||
output_offset: InlayOffset,
|
output_offset: InlayOffset,
|
||||||
max_output_offset: InlayOffset,
|
max_output_offset: InlayOffset,
|
||||||
hint_highlight_style: Option<HighlightStyle>,
|
inlay_highlight_style: Option<HighlightStyle>,
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
suggestion_highlight_style: Option<HighlightStyle>,
|
||||||
highlight_endpoints: Peekable<vec::IntoIter<HighlightEndpoint>>,
|
highlight_endpoints: Peekable<vec::IntoIter<HighlightEndpoint>>,
|
||||||
active_highlights: BTreeMap<Option<TypeId>, HighlightStyle>,
|
active_highlights: BTreeMap<Option<TypeId>, HighlightStyle>,
|
||||||
|
highlights: Highlights<'a>,
|
||||||
snapshot: &'a InlaySnapshot,
|
snapshot: &'a InlaySnapshot,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,8 +294,41 @@ impl<'a> Iterator for InlayChunks<'a> {
|
||||||
prefix
|
prefix
|
||||||
}
|
}
|
||||||
Transform::Inlay(inlay) => {
|
Transform::Inlay(inlay) => {
|
||||||
|
let mut inlay_style_and_highlight = None;
|
||||||
|
if let Some(inlay_highlights) = self.highlights.inlay_highlights {
|
||||||
|
for (_, inlay_id_to_data) in inlay_highlights.iter() {
|
||||||
|
let style_and_highlight = inlay_id_to_data.get(&inlay.id);
|
||||||
|
if style_and_highlight.is_some() {
|
||||||
|
inlay_style_and_highlight = style_and_highlight;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut highlight_style = match inlay.id {
|
||||||
|
InlayId::Suggestion(_) => self.suggestion_highlight_style,
|
||||||
|
InlayId::Hint(_) => self.inlay_highlight_style,
|
||||||
|
};
|
||||||
|
let next_inlay_highlight_endpoint;
|
||||||
|
let offset_in_inlay = self.output_offset - self.transforms.start().0;
|
||||||
|
if let Some((style, highlight)) = inlay_style_and_highlight {
|
||||||
|
let range = &highlight.range;
|
||||||
|
if offset_in_inlay.0 < range.start {
|
||||||
|
next_inlay_highlight_endpoint = range.start - offset_in_inlay.0;
|
||||||
|
} else if offset_in_inlay.0 >= range.end {
|
||||||
|
next_inlay_highlight_endpoint = usize::MAX;
|
||||||
|
} else {
|
||||||
|
next_inlay_highlight_endpoint = range.end - offset_in_inlay.0;
|
||||||
|
highlight_style
|
||||||
|
.get_or_insert_with(|| Default::default())
|
||||||
|
.highlight(style.clone());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
next_inlay_highlight_endpoint = usize::MAX;
|
||||||
|
}
|
||||||
|
|
||||||
let inlay_chunks = self.inlay_chunks.get_or_insert_with(|| {
|
let inlay_chunks = self.inlay_chunks.get_or_insert_with(|| {
|
||||||
let start = self.output_offset - self.transforms.start().0;
|
let start = offset_in_inlay;
|
||||||
let end = cmp::min(self.max_output_offset, self.transforms.end(&()).0)
|
let end = cmp::min(self.max_output_offset, self.transforms.end(&()).0)
|
||||||
- self.transforms.start().0;
|
- self.transforms.start().0;
|
||||||
inlay.text.chunks_in_range(start.0..end.0)
|
inlay.text.chunks_in_range(start.0..end.0)
|
||||||
|
@ -302,21 +336,15 @@ impl<'a> Iterator for InlayChunks<'a> {
|
||||||
let inlay_chunk = self
|
let inlay_chunk = self
|
||||||
.inlay_chunk
|
.inlay_chunk
|
||||||
.get_or_insert_with(|| inlay_chunks.next().unwrap());
|
.get_or_insert_with(|| inlay_chunks.next().unwrap());
|
||||||
let (chunk, remainder) = inlay_chunk.split_at(
|
let (chunk, remainder) =
|
||||||
inlay_chunk
|
inlay_chunk.split_at(inlay_chunk.len().min(next_inlay_highlight_endpoint));
|
||||||
.len()
|
|
||||||
.min(next_highlight_endpoint.0 - self.output_offset.0),
|
|
||||||
);
|
|
||||||
*inlay_chunk = remainder;
|
*inlay_chunk = remainder;
|
||||||
if inlay_chunk.is_empty() {
|
if inlay_chunk.is_empty() {
|
||||||
self.inlay_chunk = None;
|
self.inlay_chunk = None;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.output_offset.0 += chunk.len();
|
self.output_offset.0 += chunk.len();
|
||||||
let mut highlight_style = match inlay.id {
|
|
||||||
InlayId::Suggestion(_) => self.suggestion_highlight_style,
|
|
||||||
InlayId::Hint(_) => self.hint_highlight_style,
|
|
||||||
};
|
|
||||||
if !self.active_highlights.is_empty() {
|
if !self.active_highlights.is_empty() {
|
||||||
for active_highlight in self.active_highlights.values() {
|
for active_highlight in self.active_highlights.values() {
|
||||||
highlight_style
|
highlight_style
|
||||||
|
@ -625,18 +653,20 @@ impl InlayMap {
|
||||||
.filter(|ch| *ch != '\r')
|
.filter(|ch| *ch != '\r')
|
||||||
.take(len)
|
.take(len)
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
log::info!(
|
|
||||||
"creating inlay at buffer offset {} with bias {:?} and text {:?}",
|
|
||||||
position,
|
|
||||||
bias,
|
|
||||||
text
|
|
||||||
);
|
|
||||||
|
|
||||||
let inlay_id = if i % 2 == 0 {
|
let inlay_id = if i % 2 == 0 {
|
||||||
InlayId::Hint(post_inc(next_inlay_id))
|
InlayId::Hint(post_inc(next_inlay_id))
|
||||||
} else {
|
} else {
|
||||||
InlayId::Suggestion(post_inc(next_inlay_id))
|
InlayId::Suggestion(post_inc(next_inlay_id))
|
||||||
};
|
};
|
||||||
|
log::info!(
|
||||||
|
"creating inlay {:?} at buffer offset {} with bias {:?} and text {:?}",
|
||||||
|
inlay_id,
|
||||||
|
position,
|
||||||
|
bias,
|
||||||
|
text
|
||||||
|
);
|
||||||
|
|
||||||
to_insert.push(Inlay {
|
to_insert.push(Inlay {
|
||||||
id: inlay_id,
|
id: inlay_id,
|
||||||
position: snapshot.buffer.anchor_at(position, bias),
|
position: snapshot.buffer.anchor_at(position, bias),
|
||||||
|
@ -992,77 +1022,24 @@ impl InlaySnapshot {
|
||||||
&'a self,
|
&'a self,
|
||||||
range: Range<InlayOffset>,
|
range: Range<InlayOffset>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
highlights: Highlights<'a>,
|
||||||
hint_highlight_style: Option<HighlightStyle>,
|
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
|
||||||
) -> InlayChunks<'a> {
|
) -> InlayChunks<'a> {
|
||||||
let mut cursor = self.transforms.cursor::<(InlayOffset, usize)>();
|
let mut cursor = self.transforms.cursor::<(InlayOffset, usize)>();
|
||||||
cursor.seek(&range.start, Bias::Right, &());
|
cursor.seek(&range.start, Bias::Right, &());
|
||||||
|
|
||||||
let mut highlight_endpoints = Vec::new();
|
let mut highlight_endpoints = Vec::new();
|
||||||
if let Some(text_highlights) = text_highlights {
|
if let Some(text_highlights) = highlights.text_highlights {
|
||||||
if !text_highlights.is_empty() {
|
if !text_highlights.is_empty() {
|
||||||
while cursor.start().0 < range.end {
|
self.apply_text_highlights(
|
||||||
let transform_start = self.buffer.anchor_after(
|
&mut cursor,
|
||||||
self.to_buffer_offset(cmp::max(range.start, cursor.start().0)),
|
&range,
|
||||||
);
|
text_highlights,
|
||||||
let transform_start =
|
&mut highlight_endpoints,
|
||||||
self.to_inlay_offset(transform_start.to_offset(&self.buffer));
|
);
|
||||||
|
|
||||||
let transform_end = {
|
|
||||||
let overshoot = InlayOffset(range.end.0 - cursor.start().0 .0);
|
|
||||||
self.buffer.anchor_before(self.to_buffer_offset(cmp::min(
|
|
||||||
cursor.end(&()).0,
|
|
||||||
cursor.start().0 + overshoot,
|
|
||||||
)))
|
|
||||||
};
|
|
||||||
let transform_end = self.to_inlay_offset(transform_end.to_offset(&self.buffer));
|
|
||||||
|
|
||||||
for (tag, text_highlights) in text_highlights.iter() {
|
|
||||||
let style = text_highlights.0;
|
|
||||||
let ranges = &text_highlights.1;
|
|
||||||
|
|
||||||
let start_ix = match ranges.binary_search_by(|probe| {
|
|
||||||
let cmp = self
|
|
||||||
.document_to_inlay_range(probe)
|
|
||||||
.end
|
|
||||||
.cmp(&transform_start);
|
|
||||||
if cmp.is_gt() {
|
|
||||||
cmp::Ordering::Greater
|
|
||||||
} else {
|
|
||||||
cmp::Ordering::Less
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
Ok(i) | Err(i) => i,
|
|
||||||
};
|
|
||||||
for range in &ranges[start_ix..] {
|
|
||||||
let range = self.document_to_inlay_range(range);
|
|
||||||
if range.start.cmp(&transform_end).is_ge() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
highlight_endpoints.push(HighlightEndpoint {
|
|
||||||
offset: range.start,
|
|
||||||
is_start: true,
|
|
||||||
tag: *tag,
|
|
||||||
style,
|
|
||||||
});
|
|
||||||
highlight_endpoints.push(HighlightEndpoint {
|
|
||||||
offset: range.end,
|
|
||||||
is_start: false,
|
|
||||||
tag: *tag,
|
|
||||||
style,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cursor.next(&());
|
|
||||||
}
|
|
||||||
highlight_endpoints.sort();
|
|
||||||
cursor.seek(&range.start, Bias::Right, &());
|
cursor.seek(&range.start, Bias::Right, &());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
highlight_endpoints.sort();
|
||||||
let buffer_range = self.to_buffer_offset(range.start)..self.to_buffer_offset(range.end);
|
let buffer_range = self.to_buffer_offset(range.start)..self.to_buffer_offset(range.end);
|
||||||
let buffer_chunks = self.buffer.chunks(buffer_range, language_aware);
|
let buffer_chunks = self.buffer.chunks(buffer_range, language_aware);
|
||||||
|
|
||||||
|
@ -1074,29 +1051,76 @@ impl InlaySnapshot {
|
||||||
buffer_chunk: None,
|
buffer_chunk: None,
|
||||||
output_offset: range.start,
|
output_offset: range.start,
|
||||||
max_output_offset: range.end,
|
max_output_offset: range.end,
|
||||||
hint_highlight_style,
|
inlay_highlight_style: highlights.inlay_highlight_style,
|
||||||
suggestion_highlight_style,
|
suggestion_highlight_style: highlights.suggestion_highlight_style,
|
||||||
highlight_endpoints: highlight_endpoints.into_iter().peekable(),
|
highlight_endpoints: highlight_endpoints.into_iter().peekable(),
|
||||||
active_highlights: Default::default(),
|
active_highlights: Default::default(),
|
||||||
|
highlights,
|
||||||
snapshot: self,
|
snapshot: self,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn document_to_inlay_range(&self, range: &DocumentRange) -> Range<InlayOffset> {
|
fn apply_text_highlights(
|
||||||
match range {
|
&self,
|
||||||
DocumentRange::Text(text_range) => {
|
cursor: &mut Cursor<'_, Transform, (InlayOffset, usize)>,
|
||||||
self.to_inlay_offset(text_range.start.to_offset(&self.buffer))
|
range: &Range<InlayOffset>,
|
||||||
..self.to_inlay_offset(text_range.end.to_offset(&self.buffer))
|
text_highlights: &TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>,
|
||||||
}
|
highlight_endpoints: &mut Vec<HighlightEndpoint>,
|
||||||
DocumentRange::Inlay(inlay_range) => {
|
) {
|
||||||
inlay_range.highlight_start..inlay_range.highlight_end
|
while cursor.start().0 < range.end {
|
||||||
|
let transform_start = self
|
||||||
|
.buffer
|
||||||
|
.anchor_after(self.to_buffer_offset(cmp::max(range.start, cursor.start().0)));
|
||||||
|
let transform_end =
|
||||||
|
{
|
||||||
|
let overshoot = InlayOffset(range.end.0 - cursor.start().0 .0);
|
||||||
|
self.buffer.anchor_before(self.to_buffer_offset(cmp::min(
|
||||||
|
cursor.end(&()).0,
|
||||||
|
cursor.start().0 + overshoot,
|
||||||
|
)))
|
||||||
|
};
|
||||||
|
|
||||||
|
for (tag, text_highlights) in text_highlights.iter() {
|
||||||
|
let style = text_highlights.0;
|
||||||
|
let ranges = &text_highlights.1;
|
||||||
|
|
||||||
|
let start_ix = match ranges.binary_search_by(|probe| {
|
||||||
|
let cmp = probe.end.cmp(&transform_start, &self.buffer);
|
||||||
|
if cmp.is_gt() {
|
||||||
|
cmp::Ordering::Greater
|
||||||
|
} else {
|
||||||
|
cmp::Ordering::Less
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
Ok(i) | Err(i) => i,
|
||||||
|
};
|
||||||
|
for range in &ranges[start_ix..] {
|
||||||
|
if range.start.cmp(&transform_end, &self.buffer).is_ge() {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
highlight_endpoints.push(HighlightEndpoint {
|
||||||
|
offset: self.to_inlay_offset(range.start.to_offset(&self.buffer)),
|
||||||
|
is_start: true,
|
||||||
|
tag: *tag,
|
||||||
|
style,
|
||||||
|
});
|
||||||
|
highlight_endpoints.push(HighlightEndpoint {
|
||||||
|
offset: self.to_inlay_offset(range.end.to_offset(&self.buffer)),
|
||||||
|
is_start: false,
|
||||||
|
tag: *tag,
|
||||||
|
style,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cursor.next(&());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn text(&self) -> String {
|
pub fn text(&self) -> String {
|
||||||
self.chunks(Default::default()..self.len(), false, None, None, None)
|
self.chunks(Default::default()..self.len(), false, Highlights::default())
|
||||||
.map(|chunk| chunk.text)
|
.map(|chunk| chunk.text)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -1144,7 +1168,11 @@ fn push_isomorphic(sum_tree: &mut SumTree<Transform>, summary: TextSummary) {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{link_go_to_definition::InlayRange, InlayId, MultiBuffer};
|
use crate::{
|
||||||
|
display_map::{InlayHighlights, TextHighlights},
|
||||||
|
link_go_to_definition::InlayHighlight,
|
||||||
|
InlayId, MultiBuffer,
|
||||||
|
};
|
||||||
use gpui::AppContext;
|
use gpui::AppContext;
|
||||||
use project::{InlayHint, InlayHintLabel, ResolveState};
|
use project::{InlayHint, InlayHintLabel, ResolveState};
|
||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
|
@ -1619,8 +1647,8 @@ mod tests {
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let mut expected_text = Rope::from(buffer_snapshot.text());
|
let mut expected_text = Rope::from(buffer_snapshot.text());
|
||||||
for (offset, inlay) in inlays.into_iter().rev() {
|
for (offset, inlay) in inlays.iter().rev() {
|
||||||
expected_text.replace(offset..offset, &inlay.text.to_string());
|
expected_text.replace(*offset..*offset, &inlay.text.to_string());
|
||||||
}
|
}
|
||||||
assert_eq!(inlay_snapshot.text(), expected_text.to_string());
|
assert_eq!(inlay_snapshot.text(), expected_text.to_string());
|
||||||
|
|
||||||
|
@ -1640,51 +1668,87 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut highlights = TextHighlights::default();
|
let mut text_highlights = TextHighlights::default();
|
||||||
let highlight_count = rng.gen_range(0_usize..10);
|
let text_highlight_count = rng.gen_range(0_usize..10);
|
||||||
let mut highlight_ranges = (0..highlight_count)
|
let mut text_highlight_ranges = (0..text_highlight_count)
|
||||||
.map(|_| buffer_snapshot.random_byte_range(0, &mut rng))
|
.map(|_| buffer_snapshot.random_byte_range(0, &mut rng))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
highlight_ranges.sort_by_key(|range| (range.start, Reverse(range.end)));
|
text_highlight_ranges.sort_by_key(|range| (range.start, Reverse(range.end)));
|
||||||
log::info!("highlighting ranges {:?}", highlight_ranges);
|
log::info!("highlighting text ranges {text_highlight_ranges:?}");
|
||||||
let highlight_ranges = if rng.gen_bool(0.5) {
|
text_highlights.insert(
|
||||||
highlight_ranges
|
|
||||||
.into_iter()
|
|
||||||
.map(|range| InlayRange {
|
|
||||||
inlay_position: buffer_snapshot.anchor_before(range.start),
|
|
||||||
highlight_start: inlay_snapshot.to_inlay_offset(range.start),
|
|
||||||
highlight_end: inlay_snapshot.to_inlay_offset(range.end),
|
|
||||||
})
|
|
||||||
.map(DocumentRange::Inlay)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
} else {
|
|
||||||
highlight_ranges
|
|
||||||
.into_iter()
|
|
||||||
.map(|range| {
|
|
||||||
buffer_snapshot.anchor_before(range.start)
|
|
||||||
..buffer_snapshot.anchor_after(range.end)
|
|
||||||
})
|
|
||||||
.map(DocumentRange::Text)
|
|
||||||
.collect::<Vec<_>>()
|
|
||||||
};
|
|
||||||
highlights.insert(
|
|
||||||
Some(TypeId::of::<()>()),
|
Some(TypeId::of::<()>()),
|
||||||
Arc::new((HighlightStyle::default(), highlight_ranges)),
|
Arc::new((
|
||||||
|
HighlightStyle::default(),
|
||||||
|
text_highlight_ranges
|
||||||
|
.into_iter()
|
||||||
|
.map(|range| {
|
||||||
|
buffer_snapshot.anchor_before(range.start)
|
||||||
|
..buffer_snapshot.anchor_after(range.end)
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut inlay_highlights = InlayHighlights::default();
|
||||||
|
if !inlays.is_empty() {
|
||||||
|
let inlay_highlight_count = rng.gen_range(0..inlays.len());
|
||||||
|
let mut inlay_indices = BTreeSet::default();
|
||||||
|
while inlay_indices.len() < inlay_highlight_count {
|
||||||
|
inlay_indices.insert(rng.gen_range(0..inlays.len()));
|
||||||
|
}
|
||||||
|
let new_highlights = inlay_indices
|
||||||
|
.into_iter()
|
||||||
|
.filter_map(|i| {
|
||||||
|
let (_, inlay) = &inlays[i];
|
||||||
|
let inlay_text_len = inlay.text.len();
|
||||||
|
match inlay_text_len {
|
||||||
|
0 => None,
|
||||||
|
1 => Some(InlayHighlight {
|
||||||
|
inlay: inlay.id,
|
||||||
|
inlay_position: inlay.position,
|
||||||
|
range: 0..1,
|
||||||
|
}),
|
||||||
|
n => {
|
||||||
|
let inlay_text = inlay.text.to_string();
|
||||||
|
let mut highlight_end = rng.gen_range(1..n);
|
||||||
|
let mut highlight_start = rng.gen_range(0..highlight_end);
|
||||||
|
while !inlay_text.is_char_boundary(highlight_end) {
|
||||||
|
highlight_end += 1;
|
||||||
|
}
|
||||||
|
while !inlay_text.is_char_boundary(highlight_start) {
|
||||||
|
highlight_start -= 1;
|
||||||
|
}
|
||||||
|
Some(InlayHighlight {
|
||||||
|
inlay: inlay.id,
|
||||||
|
inlay_position: inlay.position,
|
||||||
|
range: highlight_start..highlight_end,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.map(|highlight| (highlight.inlay, (HighlightStyle::default(), highlight)))
|
||||||
|
.collect();
|
||||||
|
log::info!("highlighting inlay ranges {new_highlights:?}");
|
||||||
|
inlay_highlights.insert(TypeId::of::<()>(), new_highlights);
|
||||||
|
}
|
||||||
|
|
||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
let mut end = rng.gen_range(0..=inlay_snapshot.len().0);
|
let mut end = rng.gen_range(0..=inlay_snapshot.len().0);
|
||||||
end = expected_text.clip_offset(end, Bias::Right);
|
end = expected_text.clip_offset(end, Bias::Right);
|
||||||
let mut start = rng.gen_range(0..=end);
|
let mut start = rng.gen_range(0..=end);
|
||||||
start = expected_text.clip_offset(start, Bias::Right);
|
start = expected_text.clip_offset(start, Bias::Right);
|
||||||
|
|
||||||
|
let range = InlayOffset(start)..InlayOffset(end);
|
||||||
|
log::info!("calling inlay_snapshot.chunks({range:?})");
|
||||||
let actual_text = inlay_snapshot
|
let actual_text = inlay_snapshot
|
||||||
.chunks(
|
.chunks(
|
||||||
InlayOffset(start)..InlayOffset(end),
|
range,
|
||||||
false,
|
false,
|
||||||
Some(&highlights),
|
Highlights {
|
||||||
None,
|
text_highlights: Some(&text_highlights),
|
||||||
None,
|
inlay_highlights: Some(&inlay_highlights),
|
||||||
|
..Highlights::default()
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.map(|chunk| chunk.text)
|
.map(|chunk| chunk.text)
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
use super::{
|
use super::{
|
||||||
fold_map::{self, FoldChunks, FoldEdit, FoldPoint, FoldSnapshot},
|
fold_map::{self, FoldChunks, FoldEdit, FoldPoint, FoldSnapshot},
|
||||||
TextHighlights,
|
Highlights,
|
||||||
};
|
};
|
||||||
use crate::MultiBufferSnapshot;
|
use crate::MultiBufferSnapshot;
|
||||||
use gpui::fonts::HighlightStyle;
|
|
||||||
use language::{Chunk, Point};
|
use language::{Chunk, Point};
|
||||||
use std::{cmp, mem, num::NonZeroU32, ops::Range};
|
use std::{cmp, mem, num::NonZeroU32, ops::Range};
|
||||||
use sum_tree::Bias;
|
use sum_tree::Bias;
|
||||||
|
@ -68,9 +67,7 @@ impl TabMap {
|
||||||
'outer: for chunk in old_snapshot.fold_snapshot.chunks(
|
'outer: for chunk in old_snapshot.fold_snapshot.chunks(
|
||||||
fold_edit.old.end..old_end_row_successor_offset,
|
fold_edit.old.end..old_end_row_successor_offset,
|
||||||
false,
|
false,
|
||||||
None,
|
Highlights::default(),
|
||||||
None,
|
|
||||||
None,
|
|
||||||
) {
|
) {
|
||||||
for (ix, _) in chunk.text.match_indices('\t') {
|
for (ix, _) in chunk.text.match_indices('\t') {
|
||||||
let offset_from_edit = offset_from_edit + (ix as u32);
|
let offset_from_edit = offset_from_edit + (ix as u32);
|
||||||
|
@ -183,7 +180,7 @@ impl TabSnapshot {
|
||||||
self.max_point()
|
self.max_point()
|
||||||
};
|
};
|
||||||
for c in self
|
for c in self
|
||||||
.chunks(range.start..line_end, false, None, None, None)
|
.chunks(range.start..line_end, false, Highlights::default())
|
||||||
.flat_map(|chunk| chunk.text.chars())
|
.flat_map(|chunk| chunk.text.chars())
|
||||||
{
|
{
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
|
@ -200,9 +197,7 @@ impl TabSnapshot {
|
||||||
.chunks(
|
.chunks(
|
||||||
TabPoint::new(range.end.row(), 0)..range.end,
|
TabPoint::new(range.end.row(), 0)..range.end,
|
||||||
false,
|
false,
|
||||||
None,
|
Highlights::default(),
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.flat_map(|chunk| chunk.text.chars())
|
.flat_map(|chunk| chunk.text.chars())
|
||||||
{
|
{
|
||||||
|
@ -223,9 +218,7 @@ impl TabSnapshot {
|
||||||
&'a self,
|
&'a self,
|
||||||
range: Range<TabPoint>,
|
range: Range<TabPoint>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
highlights: Highlights<'a>,
|
||||||
hint_highlight_style: Option<HighlightStyle>,
|
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
|
||||||
) -> TabChunks<'a> {
|
) -> TabChunks<'a> {
|
||||||
let (input_start, expanded_char_column, to_next_stop) =
|
let (input_start, expanded_char_column, to_next_stop) =
|
||||||
self.to_fold_point(range.start, Bias::Left);
|
self.to_fold_point(range.start, Bias::Left);
|
||||||
|
@ -245,9 +238,7 @@ impl TabSnapshot {
|
||||||
fold_chunks: self.fold_snapshot.chunks(
|
fold_chunks: self.fold_snapshot.chunks(
|
||||||
input_start..input_end,
|
input_start..input_end,
|
||||||
language_aware,
|
language_aware,
|
||||||
text_highlights,
|
highlights,
|
||||||
hint_highlight_style,
|
|
||||||
suggestion_highlight_style,
|
|
||||||
),
|
),
|
||||||
input_column,
|
input_column,
|
||||||
column: expanded_char_column,
|
column: expanded_char_column,
|
||||||
|
@ -270,9 +261,13 @@ impl TabSnapshot {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn text(&self) -> String {
|
pub fn text(&self) -> String {
|
||||||
self.chunks(TabPoint::zero()..self.max_point(), false, None, None, None)
|
self.chunks(
|
||||||
.map(|chunk| chunk.text)
|
TabPoint::zero()..self.max_point(),
|
||||||
.collect()
|
false,
|
||||||
|
Highlights::default(),
|
||||||
|
)
|
||||||
|
.map(|chunk| chunk.text)
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max_point(&self) -> TabPoint {
|
pub fn max_point(&self) -> TabPoint {
|
||||||
|
@ -597,9 +592,7 @@ mod tests {
|
||||||
.chunks(
|
.chunks(
|
||||||
TabPoint::new(0, ix as u32)..tab_snapshot.max_point(),
|
TabPoint::new(0, ix as u32)..tab_snapshot.max_point(),
|
||||||
false,
|
false,
|
||||||
None,
|
Highlights::default(),
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
|
@ -674,7 +667,8 @@ mod tests {
|
||||||
let mut chunks = Vec::new();
|
let mut chunks = Vec::new();
|
||||||
let mut was_tab = false;
|
let mut was_tab = false;
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
for chunk in snapshot.chunks(start..snapshot.max_point(), false, None, None, None) {
|
for chunk in snapshot.chunks(start..snapshot.max_point(), false, Highlights::default())
|
||||||
|
{
|
||||||
if chunk.is_tab != was_tab {
|
if chunk.is_tab != was_tab {
|
||||||
if !text.is_empty() {
|
if !text.is_empty() {
|
||||||
chunks.push((mem::take(&mut text), was_tab));
|
chunks.push((mem::take(&mut text), was_tab));
|
||||||
|
@ -743,7 +737,7 @@ mod tests {
|
||||||
let expected_summary = TextSummary::from(expected_text.as_str());
|
let expected_summary = TextSummary::from(expected_text.as_str());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
tabs_snapshot
|
tabs_snapshot
|
||||||
.chunks(start..end, false, None, None, None)
|
.chunks(start..end, false, Highlights::default())
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
expected_text,
|
expected_text,
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
use super::{
|
use super::{
|
||||||
fold_map::FoldBufferRows,
|
fold_map::FoldBufferRows,
|
||||||
tab_map::{self, TabEdit, TabPoint, TabSnapshot},
|
tab_map::{self, TabEdit, TabPoint, TabSnapshot},
|
||||||
TextHighlights,
|
Highlights,
|
||||||
};
|
};
|
||||||
use crate::MultiBufferSnapshot;
|
use crate::MultiBufferSnapshot;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
fonts::{FontId, HighlightStyle},
|
fonts::FontId, text_layout::LineWrapper, AppContext, Entity, ModelContext, ModelHandle, Task,
|
||||||
text_layout::LineWrapper,
|
|
||||||
AppContext, Entity, ModelContext, ModelHandle, Task,
|
|
||||||
};
|
};
|
||||||
use language::{Chunk, Point};
|
use language::{Chunk, Point};
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
@ -444,9 +442,7 @@ impl WrapSnapshot {
|
||||||
let mut chunks = new_tab_snapshot.chunks(
|
let mut chunks = new_tab_snapshot.chunks(
|
||||||
TabPoint::new(edit.new_rows.start, 0)..new_tab_snapshot.max_point(),
|
TabPoint::new(edit.new_rows.start, 0)..new_tab_snapshot.max_point(),
|
||||||
false,
|
false,
|
||||||
None,
|
Highlights::default(),
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
let mut edit_transforms = Vec::<Transform>::new();
|
let mut edit_transforms = Vec::<Transform>::new();
|
||||||
for _ in edit.new_rows.start..edit.new_rows.end {
|
for _ in edit.new_rows.start..edit.new_rows.end {
|
||||||
|
@ -575,9 +571,7 @@ impl WrapSnapshot {
|
||||||
&'a self,
|
&'a self,
|
||||||
rows: Range<u32>,
|
rows: Range<u32>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
highlights: Highlights<'a>,
|
||||||
hint_highlight_style: Option<HighlightStyle>,
|
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
|
||||||
) -> WrapChunks<'a> {
|
) -> WrapChunks<'a> {
|
||||||
let output_start = WrapPoint::new(rows.start, 0);
|
let output_start = WrapPoint::new(rows.start, 0);
|
||||||
let output_end = WrapPoint::new(rows.end, 0);
|
let output_end = WrapPoint::new(rows.end, 0);
|
||||||
|
@ -594,9 +588,7 @@ impl WrapSnapshot {
|
||||||
input_chunks: self.tab_snapshot.chunks(
|
input_chunks: self.tab_snapshot.chunks(
|
||||||
input_start..input_end,
|
input_start..input_end,
|
||||||
language_aware,
|
language_aware,
|
||||||
text_highlights,
|
highlights,
|
||||||
hint_highlight_style,
|
|
||||||
suggestion_highlight_style,
|
|
||||||
),
|
),
|
||||||
input_chunk: Default::default(),
|
input_chunk: Default::default(),
|
||||||
output_position: output_start,
|
output_position: output_start,
|
||||||
|
@ -1323,9 +1315,7 @@ mod tests {
|
||||||
self.chunks(
|
self.chunks(
|
||||||
wrap_row..self.max_point().row() + 1,
|
wrap_row..self.max_point().row() + 1,
|
||||||
false,
|
false,
|
||||||
None,
|
Highlights::default(),
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.map(|h| h.text)
|
.map(|h| h.text)
|
||||||
}
|
}
|
||||||
|
@ -1350,7 +1340,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
let actual_text = self
|
let actual_text = self
|
||||||
.chunks(start_row..end_row, true, None, None, None)
|
.chunks(start_row..end_row, true, Highlights::default())
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
@ -66,7 +66,7 @@ use language::{
|
||||||
TransactionId,
|
TransactionId,
|
||||||
};
|
};
|
||||||
use link_go_to_definition::{
|
use link_go_to_definition::{
|
||||||
hide_link_definition, show_link_definition, DocumentRange, GoToDefinitionLink, InlayRange,
|
hide_link_definition, show_link_definition, GoToDefinitionLink, InlayHighlight,
|
||||||
LinkGoToDefinitionState,
|
LinkGoToDefinitionState,
|
||||||
};
|
};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
@ -99,6 +99,7 @@ use std::{
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
};
|
};
|
||||||
pub use sum_tree::Bias;
|
pub use sum_tree::Bias;
|
||||||
|
use sum_tree::TreeMap;
|
||||||
use text::Rope;
|
use text::Rope;
|
||||||
use theme::{DiagnosticStyle, Theme, ThemeSettings};
|
use theme::{DiagnosticStyle, Theme, ThemeSettings};
|
||||||
use util::{post_inc, RangeExt, ResultExt, TryFutureExt};
|
use util::{post_inc, RangeExt, ResultExt, TryFutureExt};
|
||||||
|
@ -548,7 +549,8 @@ type CompletionId = usize;
|
||||||
type GetFieldEditorTheme = dyn Fn(&theme::Theme) -> theme::FieldEditor;
|
type GetFieldEditorTheme = dyn Fn(&theme::Theme) -> theme::FieldEditor;
|
||||||
type OverrideTextStyle = dyn Fn(&EditorStyle) -> Option<HighlightStyle>;
|
type OverrideTextStyle = dyn Fn(&EditorStyle) -> Option<HighlightStyle>;
|
||||||
|
|
||||||
type BackgroundHighlight = (fn(&Theme) -> Color, Vec<DocumentRange>);
|
type BackgroundHighlight = (fn(&Theme) -> Color, Vec<Range<Anchor>>);
|
||||||
|
type InlayBackgroundHighlight = (fn(&Theme) -> Color, Vec<InlayHighlight>);
|
||||||
|
|
||||||
pub struct Editor {
|
pub struct Editor {
|
||||||
handle: WeakViewHandle<Self>,
|
handle: WeakViewHandle<Self>,
|
||||||
|
@ -580,6 +582,7 @@ pub struct Editor {
|
||||||
placeholder_text: Option<Arc<str>>,
|
placeholder_text: Option<Arc<str>>,
|
||||||
highlighted_rows: Option<Range<u32>>,
|
highlighted_rows: Option<Range<u32>>,
|
||||||
background_highlights: BTreeMap<TypeId, BackgroundHighlight>,
|
background_highlights: BTreeMap<TypeId, BackgroundHighlight>,
|
||||||
|
inlay_background_highlights: TreeMap<Option<TypeId>, InlayBackgroundHighlight>,
|
||||||
nav_history: Option<ItemNavHistory>,
|
nav_history: Option<ItemNavHistory>,
|
||||||
context_menu: Option<ContextMenu>,
|
context_menu: Option<ContextMenu>,
|
||||||
mouse_context_menu: ViewHandle<context_menu::ContextMenu>,
|
mouse_context_menu: ViewHandle<context_menu::ContextMenu>,
|
||||||
|
@ -1523,6 +1526,7 @@ impl Editor {
|
||||||
placeholder_text: None,
|
placeholder_text: None,
|
||||||
highlighted_rows: None,
|
highlighted_rows: None,
|
||||||
background_highlights: Default::default(),
|
background_highlights: Default::default(),
|
||||||
|
inlay_background_highlights: Default::default(),
|
||||||
nav_history: None,
|
nav_history: None,
|
||||||
context_menu: None,
|
context_menu: None,
|
||||||
mouse_context_menu: cx
|
mouse_context_menu: cx
|
||||||
|
@ -7066,16 +7070,8 @@ impl Editor {
|
||||||
} else {
|
} else {
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
let buffer = this.buffer.read(cx).snapshot(cx);
|
let buffer = this.buffer.read(cx).snapshot(cx);
|
||||||
let display_snapshot = this
|
|
||||||
.display_map
|
|
||||||
.update(cx, |display_map, cx| display_map.snapshot(cx));
|
|
||||||
let mut buffer_highlights = this
|
let mut buffer_highlights = this
|
||||||
.document_highlights_for_position(
|
.document_highlights_for_position(selection.head(), &buffer)
|
||||||
selection.head(),
|
|
||||||
&buffer,
|
|
||||||
&display_snapshot,
|
|
||||||
)
|
|
||||||
.filter_map(|highlight| highlight.as_text_range())
|
|
||||||
.filter(|highlight| {
|
.filter(|highlight| {
|
||||||
highlight.start.excerpt_id() == selection.head().excerpt_id()
|
highlight.start.excerpt_id() == selection.head().excerpt_id()
|
||||||
&& highlight.end.excerpt_id() == selection.head().excerpt_id()
|
&& highlight.end.excerpt_id() == selection.head().excerpt_id()
|
||||||
|
@ -7130,15 +7126,11 @@ impl Editor {
|
||||||
let ranges = this
|
let ranges = this
|
||||||
.clear_background_highlights::<DocumentHighlightWrite>(cx)
|
.clear_background_highlights::<DocumentHighlightWrite>(cx)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|(_, ranges)| {
|
.flat_map(|(_, ranges)| ranges.into_iter())
|
||||||
ranges.into_iter().filter_map(|range| range.as_text_range())
|
|
||||||
})
|
|
||||||
.chain(
|
.chain(
|
||||||
this.clear_background_highlights::<DocumentHighlightRead>(cx)
|
this.clear_background_highlights::<DocumentHighlightRead>(cx)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.flat_map(|(_, ranges)| {
|
.flat_map(|(_, ranges)| ranges.into_iter()),
|
||||||
ranges.into_iter().filter_map(|range| range.as_text_range())
|
|
||||||
}),
|
|
||||||
)
|
)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -7239,7 +7231,7 @@ impl Editor {
|
||||||
Some(Autoscroll::fit()),
|
Some(Autoscroll::fit()),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
self.clear_text_highlights::<Rename>(cx);
|
self.clear_highlights::<Rename>(cx);
|
||||||
self.show_local_selections = true;
|
self.show_local_selections = true;
|
||||||
|
|
||||||
if moving_cursor {
|
if moving_cursor {
|
||||||
|
@ -7816,29 +7808,20 @@ impl Editor {
|
||||||
color_fetcher: fn(&Theme) -> Color,
|
color_fetcher: fn(&Theme) -> Color,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
self.background_highlights.insert(
|
self.background_highlights
|
||||||
TypeId::of::<T>(),
|
.insert(TypeId::of::<T>(), (color_fetcher, ranges));
|
||||||
(
|
|
||||||
color_fetcher,
|
|
||||||
ranges.into_iter().map(DocumentRange::Text).collect(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn highlight_inlay_background<T: 'static>(
|
pub fn highlight_inlay_background<T: 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
ranges: Vec<InlayRange>,
|
ranges: Vec<InlayHighlight>,
|
||||||
color_fetcher: fn(&Theme) -> Color,
|
color_fetcher: fn(&Theme) -> Color,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
self.background_highlights.insert(
|
// TODO: no actual highlights happen for inlays currently, find a way to do that
|
||||||
TypeId::of::<T>(),
|
self.inlay_background_highlights
|
||||||
(
|
.insert(Some(TypeId::of::<T>()), (color_fetcher, ranges));
|
||||||
color_fetcher,
|
|
||||||
ranges.into_iter().map(DocumentRange::Inlay).collect(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7846,15 +7829,18 @@ impl Editor {
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Option<BackgroundHighlight> {
|
) -> Option<BackgroundHighlight> {
|
||||||
let highlights = self.background_highlights.remove(&TypeId::of::<T>());
|
let text_highlights = self.background_highlights.remove(&TypeId::of::<T>());
|
||||||
if highlights.is_some() {
|
let inlay_highlights = self
|
||||||
|
.inlay_background_highlights
|
||||||
|
.remove(&Some(TypeId::of::<T>()));
|
||||||
|
if text_highlights.is_some() || inlay_highlights.is_some() {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
highlights
|
text_highlights
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "test-support")]
|
#[cfg(feature = "test-support")]
|
||||||
pub fn all_background_highlights(
|
pub fn all_text_background_highlights(
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Vec<(Range<DisplayPoint>, Color)> {
|
) -> Vec<(Range<DisplayPoint>, Color)> {
|
||||||
|
@ -7870,8 +7856,7 @@ impl Editor {
|
||||||
&'a self,
|
&'a self,
|
||||||
position: Anchor,
|
position: Anchor,
|
||||||
buffer: &'a MultiBufferSnapshot,
|
buffer: &'a MultiBufferSnapshot,
|
||||||
display_snapshot: &'a DisplaySnapshot,
|
) -> impl 'a + Iterator<Item = &Range<Anchor>> {
|
||||||
) -> impl 'a + Iterator<Item = &DocumentRange> {
|
|
||||||
let read_highlights = self
|
let read_highlights = self
|
||||||
.background_highlights
|
.background_highlights
|
||||||
.get(&TypeId::of::<DocumentHighlightRead>())
|
.get(&TypeId::of::<DocumentHighlightRead>())
|
||||||
|
@ -7880,16 +7865,14 @@ impl Editor {
|
||||||
.background_highlights
|
.background_highlights
|
||||||
.get(&TypeId::of::<DocumentHighlightWrite>())
|
.get(&TypeId::of::<DocumentHighlightWrite>())
|
||||||
.map(|h| &h.1);
|
.map(|h| &h.1);
|
||||||
let left_position = display_snapshot.anchor_to_inlay_offset(position.bias_left(buffer));
|
let left_position = position.bias_left(buffer);
|
||||||
let right_position = display_snapshot.anchor_to_inlay_offset(position.bias_right(buffer));
|
let right_position = position.bias_right(buffer);
|
||||||
read_highlights
|
read_highlights
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.chain(write_highlights)
|
.chain(write_highlights)
|
||||||
.flat_map(move |ranges| {
|
.flat_map(move |ranges| {
|
||||||
let start_ix = match ranges.binary_search_by(|probe| {
|
let start_ix = match ranges.binary_search_by(|probe| {
|
||||||
let cmp = document_to_inlay_range(probe, display_snapshot)
|
let cmp = probe.end.cmp(&left_position, buffer);
|
||||||
.end
|
|
||||||
.cmp(&left_position);
|
|
||||||
if cmp.is_ge() {
|
if cmp.is_ge() {
|
||||||
Ordering::Greater
|
Ordering::Greater
|
||||||
} else {
|
} else {
|
||||||
|
@ -7900,12 +7883,9 @@ impl Editor {
|
||||||
};
|
};
|
||||||
|
|
||||||
let right_position = right_position.clone();
|
let right_position = right_position.clone();
|
||||||
ranges[start_ix..].iter().take_while(move |range| {
|
ranges[start_ix..]
|
||||||
document_to_inlay_range(range, display_snapshot)
|
.iter()
|
||||||
.start
|
.take_while(move |range| range.start.cmp(&right_position, buffer).is_le())
|
||||||
.cmp(&right_position)
|
|
||||||
.is_le()
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7915,15 +7895,13 @@ impl Editor {
|
||||||
display_snapshot: &DisplaySnapshot,
|
display_snapshot: &DisplaySnapshot,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
) -> Vec<(Range<DisplayPoint>, Color)> {
|
) -> Vec<(Range<DisplayPoint>, Color)> {
|
||||||
let search_range = display_snapshot.anchor_to_inlay_offset(search_range.start)
|
|
||||||
..display_snapshot.anchor_to_inlay_offset(search_range.end);
|
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
for (color_fetcher, ranges) in self.background_highlights.values() {
|
for (color_fetcher, ranges) in self.background_highlights.values() {
|
||||||
let color = color_fetcher(theme);
|
let color = color_fetcher(theme);
|
||||||
let start_ix = match ranges.binary_search_by(|probe| {
|
let start_ix = match ranges.binary_search_by(|probe| {
|
||||||
let cmp = document_to_inlay_range(probe, display_snapshot)
|
let cmp = probe
|
||||||
.end
|
.end
|
||||||
.cmp(&search_range.start);
|
.cmp(&search_range.start, &display_snapshot.buffer_snapshot);
|
||||||
if cmp.is_gt() {
|
if cmp.is_gt() {
|
||||||
Ordering::Greater
|
Ordering::Greater
|
||||||
} else {
|
} else {
|
||||||
|
@ -7933,13 +7911,16 @@ impl Editor {
|
||||||
Ok(i) | Err(i) => i,
|
Ok(i) | Err(i) => i,
|
||||||
};
|
};
|
||||||
for range in &ranges[start_ix..] {
|
for range in &ranges[start_ix..] {
|
||||||
let range = document_to_inlay_range(range, display_snapshot);
|
if range
|
||||||
if range.start.cmp(&search_range.end).is_ge() {
|
.start
|
||||||
|
.cmp(&search_range.end, &display_snapshot.buffer_snapshot)
|
||||||
|
.is_ge()
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
let start = display_snapshot.inlay_offset_to_display_point(range.start, Bias::Left);
|
let start = range.start.to_display_point(&display_snapshot);
|
||||||
let end = display_snapshot.inlay_offset_to_display_point(range.end, Bias::Right);
|
let end = range.end.to_display_point(&display_snapshot);
|
||||||
results.push((start..end, color))
|
results.push((start..end, color))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7952,17 +7933,15 @@ impl Editor {
|
||||||
display_snapshot: &DisplaySnapshot,
|
display_snapshot: &DisplaySnapshot,
|
||||||
count: usize,
|
count: usize,
|
||||||
) -> Vec<RangeInclusive<DisplayPoint>> {
|
) -> Vec<RangeInclusive<DisplayPoint>> {
|
||||||
let search_range = display_snapshot.anchor_to_inlay_offset(search_range.start)
|
|
||||||
..display_snapshot.anchor_to_inlay_offset(search_range.end);
|
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
let Some((_, ranges)) = self.background_highlights.get(&TypeId::of::<T>()) else {
|
let Some((_, ranges)) = self.background_highlights.get(&TypeId::of::<T>()) else {
|
||||||
return vec![];
|
return vec![];
|
||||||
};
|
};
|
||||||
|
|
||||||
let start_ix = match ranges.binary_search_by(|probe| {
|
let start_ix = match ranges.binary_search_by(|probe| {
|
||||||
let cmp = document_to_inlay_range(probe, display_snapshot)
|
let cmp = probe
|
||||||
.end
|
.end
|
||||||
.cmp(&search_range.start);
|
.cmp(&search_range.start, &display_snapshot.buffer_snapshot);
|
||||||
if cmp.is_gt() {
|
if cmp.is_gt() {
|
||||||
Ordering::Greater
|
Ordering::Greater
|
||||||
} else {
|
} else {
|
||||||
|
@ -7985,22 +7964,20 @@ impl Editor {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
}
|
}
|
||||||
for range in &ranges[start_ix..] {
|
for range in &ranges[start_ix..] {
|
||||||
let range = document_to_inlay_range(range, display_snapshot);
|
if range
|
||||||
if range.start.cmp(&search_range.end).is_ge() {
|
.start
|
||||||
|
.cmp(&search_range.end, &display_snapshot.buffer_snapshot)
|
||||||
|
.is_ge()
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let end = display_snapshot
|
let end = range.end.to_point(&display_snapshot.buffer_snapshot);
|
||||||
.inlay_offset_to_display_point(range.end, Bias::Right)
|
|
||||||
.to_point(display_snapshot);
|
|
||||||
if let Some(current_row) = &end_row {
|
if let Some(current_row) = &end_row {
|
||||||
if end.row == current_row.row {
|
if end.row == current_row.row {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let start = display_snapshot
|
let start = range.start.to_point(&display_snapshot.buffer_snapshot);
|
||||||
.inlay_offset_to_display_point(range.start, Bias::Left)
|
|
||||||
.to_point(display_snapshot);
|
|
||||||
|
|
||||||
if start_row.is_none() {
|
if start_row.is_none() {
|
||||||
assert_eq!(end_row, None);
|
assert_eq!(end_row, None);
|
||||||
start_row = Some(start);
|
start_row = Some(start);
|
||||||
|
@ -8039,12 +8016,12 @@ impl Editor {
|
||||||
|
|
||||||
pub fn highlight_inlays<T: 'static>(
|
pub fn highlight_inlays<T: 'static>(
|
||||||
&mut self,
|
&mut self,
|
||||||
ranges: Vec<InlayRange>,
|
highlights: Vec<InlayHighlight>,
|
||||||
style: HighlightStyle,
|
style: HighlightStyle,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
self.display_map.update(cx, |map, _| {
|
self.display_map.update(cx, |map, _| {
|
||||||
map.highlight_inlays(TypeId::of::<T>(), ranges, style)
|
map.highlight_inlays(TypeId::of::<T>(), highlights, style)
|
||||||
});
|
});
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
|
@ -8052,15 +8029,15 @@ impl Editor {
|
||||||
pub fn text_highlights<'a, T: 'static>(
|
pub fn text_highlights<'a, T: 'static>(
|
||||||
&'a self,
|
&'a self,
|
||||||
cx: &'a AppContext,
|
cx: &'a AppContext,
|
||||||
) -> Option<(HighlightStyle, &'a [DocumentRange])> {
|
) -> Option<(HighlightStyle, &'a [Range<Anchor>])> {
|
||||||
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>(&mut self, cx: &mut ViewContext<Self>) {
|
pub fn clear_highlights<T: 'static>(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
let text_highlights = self
|
let cleared = self
|
||||||
.display_map
|
.display_map
|
||||||
.update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()));
|
.update(cx, |map, _| map.clear_highlights(TypeId::of::<T>()));
|
||||||
if text_highlights.is_some() {
|
if cleared {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8277,7 +8254,6 @@ impl Editor {
|
||||||
Some(
|
Some(
|
||||||
ranges
|
ranges
|
||||||
.iter()
|
.iter()
|
||||||
.filter_map(|range| range.as_text_range())
|
|
||||||
.map(move |range| {
|
.map(move |range| {
|
||||||
range.start.to_offset_utf16(&snapshot)..range.end.to_offset_utf16(&snapshot)
|
range.start.to_offset_utf16(&snapshot)..range.end.to_offset_utf16(&snapshot)
|
||||||
})
|
})
|
||||||
|
@ -8492,19 +8468,6 @@ impl Editor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn document_to_inlay_range(
|
|
||||||
range: &DocumentRange,
|
|
||||||
snapshot: &DisplaySnapshot,
|
|
||||||
) -> Range<InlayOffset> {
|
|
||||||
match range {
|
|
||||||
DocumentRange::Text(text_range) => {
|
|
||||||
snapshot.anchor_to_inlay_offset(text_range.start)
|
|
||||||
..snapshot.anchor_to_inlay_offset(text_range.end)
|
|
||||||
}
|
|
||||||
DocumentRange::Inlay(inlay_range) => inlay_range.highlight_start..inlay_range.highlight_end,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn inlay_hint_settings(
|
fn inlay_hint_settings(
|
||||||
location: Anchor,
|
location: Anchor,
|
||||||
snapshot: &MultiBufferSnapshot,
|
snapshot: &MultiBufferSnapshot,
|
||||||
|
@ -8715,7 +8678,7 @@ impl View for Editor {
|
||||||
|
|
||||||
self.link_go_to_definition_state.task = None;
|
self.link_go_to_definition_state.task = None;
|
||||||
|
|
||||||
self.clear_text_highlights::<LinkGoToDefinitionState>(cx);
|
self.clear_highlights::<LinkGoToDefinitionState>(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
false
|
false
|
||||||
|
@ -8784,12 +8747,11 @@ impl View for Editor {
|
||||||
fn marked_text_range(&self, cx: &AppContext) -> Option<Range<usize>> {
|
fn marked_text_range(&self, cx: &AppContext) -> Option<Range<usize>> {
|
||||||
let snapshot = self.buffer.read(cx).read(cx);
|
let snapshot = self.buffer.read(cx).read(cx);
|
||||||
let range = self.text_highlights::<InputComposition>(cx)?.1.get(0)?;
|
let range = self.text_highlights::<InputComposition>(cx)?.1.get(0)?;
|
||||||
let range = range.as_text_range()?;
|
|
||||||
Some(range.start.to_offset_utf16(&snapshot).0..range.end.to_offset_utf16(&snapshot).0)
|
Some(range.start.to_offset_utf16(&snapshot).0..range.end.to_offset_utf16(&snapshot).0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unmark_text(&mut self, cx: &mut ViewContext<Self>) {
|
fn unmark_text(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
self.clear_text_highlights::<InputComposition>(cx);
|
self.clear_highlights::<InputComposition>(cx);
|
||||||
self.ime_transaction.take();
|
self.ime_transaction.take();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
display_map::{InlayOffset, ToDisplayPoint},
|
display_map::{InlayOffset, ToDisplayPoint},
|
||||||
link_go_to_definition::{DocumentRange, InlayRange},
|
link_go_to_definition::{InlayHighlight, RangeInEditor},
|
||||||
Anchor, AnchorRangeExt, DisplayPoint, Editor, EditorSettings, EditorSnapshot, EditorStyle,
|
Anchor, AnchorRangeExt, DisplayPoint, Editor, EditorSettings, EditorSnapshot, EditorStyle,
|
||||||
ExcerptId, RangeToAnchorExt,
|
ExcerptId, RangeToAnchorExt,
|
||||||
};
|
};
|
||||||
|
@ -50,19 +50,18 @@ pub fn hover_at(editor: &mut Editor, point: Option<DisplayPoint>, cx: &mut ViewC
|
||||||
|
|
||||||
pub struct InlayHover {
|
pub struct InlayHover {
|
||||||
pub excerpt: ExcerptId,
|
pub excerpt: ExcerptId,
|
||||||
pub triggered_from: InlayOffset,
|
pub range: InlayHighlight,
|
||||||
pub range: InlayRange,
|
|
||||||
pub tooltip: HoverBlock,
|
pub tooltip: HoverBlock,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn find_hovered_hint_part(
|
pub fn find_hovered_hint_part(
|
||||||
label_parts: Vec<InlayHintLabelPart>,
|
label_parts: Vec<InlayHintLabelPart>,
|
||||||
hint_range: Range<InlayOffset>,
|
hint_start: InlayOffset,
|
||||||
hovered_offset: InlayOffset,
|
hovered_offset: InlayOffset,
|
||||||
) -> Option<(InlayHintLabelPart, Range<InlayOffset>)> {
|
) -> Option<(InlayHintLabelPart, Range<InlayOffset>)> {
|
||||||
if hovered_offset >= hint_range.start && hovered_offset <= hint_range.end {
|
if hovered_offset >= hint_start {
|
||||||
let mut hovered_character = (hovered_offset - hint_range.start).0;
|
let mut hovered_character = (hovered_offset - hint_start).0;
|
||||||
let mut part_start = hint_range.start;
|
let mut part_start = hint_start;
|
||||||
for part in label_parts {
|
for part in label_parts {
|
||||||
let part_len = part.value.chars().count();
|
let part_len = part.value.chars().count();
|
||||||
if hovered_character > part_len {
|
if hovered_character > part_len {
|
||||||
|
@ -88,10 +87,8 @@ pub fn hover_at_inlay(editor: &mut Editor, inlay_hover: InlayHover, cx: &mut Vie
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(InfoPopover { symbol_range, .. }) = &editor.hover_state.info_popover {
|
if let Some(InfoPopover { symbol_range, .. }) = &editor.hover_state.info_popover {
|
||||||
if let DocumentRange::Inlay(range) = symbol_range {
|
if let RangeInEditor::Inlay(range) = symbol_range {
|
||||||
if (range.highlight_start..range.highlight_end)
|
if range == &inlay_hover.range {
|
||||||
.contains(&inlay_hover.triggered_from)
|
|
||||||
{
|
|
||||||
// Hover triggered from same location as last time. Don't show again.
|
// Hover triggered from same location as last time. Don't show again.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -99,18 +96,6 @@ pub fn hover_at_inlay(editor: &mut Editor, inlay_hover: InlayHover, cx: &mut Vie
|
||||||
hide_hover(editor, cx);
|
hide_hover(editor, cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
let snapshot = editor.snapshot(cx);
|
|
||||||
// Don't request again if the location is the same as the previous request
|
|
||||||
if let Some(triggered_from) = editor.hover_state.triggered_from {
|
|
||||||
if inlay_hover.triggered_from
|
|
||||||
== snapshot
|
|
||||||
.display_snapshot
|
|
||||||
.anchor_to_inlay_offset(triggered_from)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let task = cx.spawn(|this, mut cx| {
|
let task = cx.spawn(|this, mut cx| {
|
||||||
async move {
|
async move {
|
||||||
cx.background()
|
cx.background()
|
||||||
|
@ -122,7 +107,7 @@ pub fn hover_at_inlay(editor: &mut Editor, inlay_hover: InlayHover, cx: &mut Vie
|
||||||
|
|
||||||
let hover_popover = InfoPopover {
|
let hover_popover = InfoPopover {
|
||||||
project: project.clone(),
|
project: project.clone(),
|
||||||
symbol_range: DocumentRange::Inlay(inlay_hover.range),
|
symbol_range: RangeInEditor::Inlay(inlay_hover.range.clone()),
|
||||||
blocks: vec![inlay_hover.tooltip],
|
blocks: vec![inlay_hover.tooltip],
|
||||||
language: None,
|
language: None,
|
||||||
rendered_content: None,
|
rendered_content: None,
|
||||||
|
@ -326,7 +311,7 @@ fn show_hover(
|
||||||
|
|
||||||
Some(InfoPopover {
|
Some(InfoPopover {
|
||||||
project: project.clone(),
|
project: project.clone(),
|
||||||
symbol_range: DocumentRange::Text(range),
|
symbol_range: RangeInEditor::Text(range),
|
||||||
blocks: hover_result.contents,
|
blocks: hover_result.contents,
|
||||||
language: hover_result.language,
|
language: hover_result.language,
|
||||||
rendered_content: None,
|
rendered_content: None,
|
||||||
|
@ -608,8 +593,8 @@ impl HoverState {
|
||||||
self.info_popover
|
self.info_popover
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|info_popover| match &info_popover.symbol_range {
|
.map(|info_popover| match &info_popover.symbol_range {
|
||||||
DocumentRange::Text(range) => &range.start,
|
RangeInEditor::Text(range) => &range.start,
|
||||||
DocumentRange::Inlay(range) => &range.inlay_position,
|
RangeInEditor::Inlay(range) => &range.inlay_position,
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
let point = anchor.to_display_point(&snapshot.display_snapshot);
|
let point = anchor.to_display_point(&snapshot.display_snapshot);
|
||||||
|
@ -635,7 +620,7 @@ impl HoverState {
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct InfoPopover {
|
pub struct InfoPopover {
|
||||||
pub project: ModelHandle<Project>,
|
pub project: ModelHandle<Project>,
|
||||||
symbol_range: DocumentRange,
|
symbol_range: RangeInEditor,
|
||||||
pub blocks: Vec<HoverBlock>,
|
pub blocks: Vec<HoverBlock>,
|
||||||
language: Option<Arc<Language>>,
|
language: Option<Arc<Language>>,
|
||||||
rendered_content: Option<RenderedInfo>,
|
rendered_content: Option<RenderedInfo>,
|
||||||
|
@ -811,6 +796,7 @@ mod tests {
|
||||||
inlay_hint_cache::tests::{cached_hint_labels, visible_hint_labels},
|
inlay_hint_cache::tests::{cached_hint_labels, visible_hint_labels},
|
||||||
link_go_to_definition::update_inlay_link_and_hover_points,
|
link_go_to_definition::update_inlay_link_and_hover_points,
|
||||||
test::editor_lsp_test_context::EditorLspTestContext,
|
test::editor_lsp_test_context::EditorLspTestContext,
|
||||||
|
InlayId,
|
||||||
};
|
};
|
||||||
use collections::BTreeSet;
|
use collections::BTreeSet;
|
||||||
use gpui::fonts::Weight;
|
use gpui::fonts::Weight;
|
||||||
|
@ -1477,25 +1463,16 @@ mod tests {
|
||||||
.advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));
|
.advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
let snapshot = editor.snapshot(cx);
|
|
||||||
let hover_state = &editor.hover_state;
|
let hover_state = &editor.hover_state;
|
||||||
assert!(hover_state.diagnostic_popover.is_none() && hover_state.info_popover.is_some());
|
assert!(hover_state.diagnostic_popover.is_none() && hover_state.info_popover.is_some());
|
||||||
let popover = hover_state.info_popover.as_ref().unwrap();
|
let popover = hover_state.info_popover.as_ref().unwrap();
|
||||||
let buffer_snapshot = editor.buffer().update(cx, |buffer, cx| buffer.snapshot(cx));
|
let buffer_snapshot = editor.buffer().update(cx, |buffer, cx| buffer.snapshot(cx));
|
||||||
let entire_inlay_start = snapshot.display_point_to_inlay_offset(
|
|
||||||
inlay_range.start.to_display_point(&snapshot),
|
|
||||||
Bias::Left,
|
|
||||||
);
|
|
||||||
|
|
||||||
let expected_new_type_label_start = InlayOffset(entire_inlay_start.0 + ": ".len());
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
popover.symbol_range,
|
popover.symbol_range,
|
||||||
DocumentRange::Inlay(InlayRange {
|
RangeInEditor::Inlay(InlayHighlight {
|
||||||
|
inlay: InlayId::Hint(0),
|
||||||
inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right),
|
inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right),
|
||||||
highlight_start: expected_new_type_label_start,
|
range: ": ".len()..": ".len() + new_type_label.len(),
|
||||||
highlight_end: InlayOffset(
|
|
||||||
expected_new_type_label_start.0 + new_type_label.len()
|
|
||||||
),
|
|
||||||
}),
|
}),
|
||||||
"Popover range should match the new type label part"
|
"Popover range should match the new type label part"
|
||||||
);
|
);
|
||||||
|
@ -1543,23 +1520,17 @@ mod tests {
|
||||||
.advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));
|
.advance_clock(Duration::from_millis(HOVER_DELAY_MILLIS + 100));
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
let snapshot = editor.snapshot(cx);
|
|
||||||
let hover_state = &editor.hover_state;
|
let hover_state = &editor.hover_state;
|
||||||
assert!(hover_state.diagnostic_popover.is_none() && hover_state.info_popover.is_some());
|
assert!(hover_state.diagnostic_popover.is_none() && hover_state.info_popover.is_some());
|
||||||
let popover = hover_state.info_popover.as_ref().unwrap();
|
let popover = hover_state.info_popover.as_ref().unwrap();
|
||||||
let buffer_snapshot = editor.buffer().update(cx, |buffer, cx| buffer.snapshot(cx));
|
let buffer_snapshot = editor.buffer().update(cx, |buffer, cx| buffer.snapshot(cx));
|
||||||
let entire_inlay_start = snapshot.display_point_to_inlay_offset(
|
|
||||||
inlay_range.start.to_display_point(&snapshot),
|
|
||||||
Bias::Left,
|
|
||||||
);
|
|
||||||
let expected_struct_label_start =
|
|
||||||
InlayOffset(entire_inlay_start.0 + ": ".len() + new_type_label.len() + "<".len());
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
popover.symbol_range,
|
popover.symbol_range,
|
||||||
DocumentRange::Inlay(InlayRange {
|
RangeInEditor::Inlay(InlayHighlight {
|
||||||
|
inlay: InlayId::Hint(0),
|
||||||
inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right),
|
inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right),
|
||||||
highlight_start: expected_struct_label_start,
|
range: ": ".len() + new_type_label.len() + "<".len()
|
||||||
highlight_end: InlayOffset(expected_struct_label_start.0 + struct_label.len()),
|
..": ".len() + new_type_label.len() + "<".len() + struct_label.len(),
|
||||||
}),
|
}),
|
||||||
"Popover range should match the struct label part"
|
"Popover range should match the struct label part"
|
||||||
);
|
);
|
||||||
|
|
|
@ -43,7 +43,8 @@ pub struct CachedExcerptHints {
|
||||||
version: usize,
|
version: usize,
|
||||||
buffer_version: Global,
|
buffer_version: Global,
|
||||||
buffer_id: u64,
|
buffer_id: u64,
|
||||||
hints: Vec<(InlayId, InlayHint)>,
|
ordered_hints: Vec<InlayId>,
|
||||||
|
hints_by_id: HashMap<InlayId, InlayHint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
@ -316,7 +317,7 @@ impl InlayHintCache {
|
||||||
self.hints.retain(|cached_excerpt, cached_hints| {
|
self.hints.retain(|cached_excerpt, cached_hints| {
|
||||||
let retain = excerpts_to_query.contains_key(cached_excerpt);
|
let retain = excerpts_to_query.contains_key(cached_excerpt);
|
||||||
if !retain {
|
if !retain {
|
||||||
invalidated_hints.extend(cached_hints.read().hints.iter().map(|&(id, _)| id));
|
invalidated_hints.extend(cached_hints.read().ordered_hints.iter().copied());
|
||||||
}
|
}
|
||||||
retain
|
retain
|
||||||
});
|
});
|
||||||
|
@ -384,7 +385,7 @@ impl InlayHintCache {
|
||||||
let shown_excerpt_hints_to_remove =
|
let shown_excerpt_hints_to_remove =
|
||||||
shown_hints_to_remove.entry(*excerpt_id).or_default();
|
shown_hints_to_remove.entry(*excerpt_id).or_default();
|
||||||
let excerpt_cached_hints = excerpt_cached_hints.read();
|
let excerpt_cached_hints = excerpt_cached_hints.read();
|
||||||
let mut excerpt_cache = excerpt_cached_hints.hints.iter().fuse().peekable();
|
let mut excerpt_cache = excerpt_cached_hints.ordered_hints.iter().fuse().peekable();
|
||||||
shown_excerpt_hints_to_remove.retain(|(shown_anchor, shown_hint_id)| {
|
shown_excerpt_hints_to_remove.retain(|(shown_anchor, shown_hint_id)| {
|
||||||
let Some(buffer) = shown_anchor
|
let Some(buffer) = shown_anchor
|
||||||
.buffer_id
|
.buffer_id
|
||||||
|
@ -395,7 +396,8 @@ impl InlayHintCache {
|
||||||
let buffer_snapshot = buffer.read(cx).snapshot();
|
let buffer_snapshot = buffer.read(cx).snapshot();
|
||||||
loop {
|
loop {
|
||||||
match excerpt_cache.peek() {
|
match excerpt_cache.peek() {
|
||||||
Some((cached_hint_id, cached_hint)) => {
|
Some(&cached_hint_id) => {
|
||||||
|
let cached_hint = &excerpt_cached_hints.hints_by_id[cached_hint_id];
|
||||||
if cached_hint_id == shown_hint_id {
|
if cached_hint_id == shown_hint_id {
|
||||||
excerpt_cache.next();
|
excerpt_cache.next();
|
||||||
return !new_kinds.contains(&cached_hint.kind);
|
return !new_kinds.contains(&cached_hint.kind);
|
||||||
|
@ -428,7 +430,8 @@ impl InlayHintCache {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
for (cached_hint_id, maybe_missed_cached_hint) in excerpt_cache {
|
for cached_hint_id in excerpt_cache {
|
||||||
|
let maybe_missed_cached_hint = &excerpt_cached_hints.hints_by_id[cached_hint_id];
|
||||||
let cached_hint_kind = maybe_missed_cached_hint.kind;
|
let cached_hint_kind = maybe_missed_cached_hint.kind;
|
||||||
if !old_kinds.contains(&cached_hint_kind) && new_kinds.contains(&cached_hint_kind) {
|
if !old_kinds.contains(&cached_hint_kind) && new_kinds.contains(&cached_hint_kind) {
|
||||||
to_insert.push(Inlay::hint(
|
to_insert.push(Inlay::hint(
|
||||||
|
@ -463,7 +466,7 @@ impl InlayHintCache {
|
||||||
self.update_tasks.remove(&excerpt_to_remove);
|
self.update_tasks.remove(&excerpt_to_remove);
|
||||||
if let Some(cached_hints) = self.hints.remove(&excerpt_to_remove) {
|
if let Some(cached_hints) = self.hints.remove(&excerpt_to_remove) {
|
||||||
let cached_hints = cached_hints.read();
|
let cached_hints = cached_hints.read();
|
||||||
to_remove.extend(cached_hints.hints.iter().map(|(id, _)| *id));
|
to_remove.extend(cached_hints.ordered_hints.iter().copied());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if to_remove.is_empty() {
|
if to_remove.is_empty() {
|
||||||
|
@ -489,10 +492,8 @@ impl InlayHintCache {
|
||||||
self.hints
|
self.hints
|
||||||
.get(&excerpt_id)?
|
.get(&excerpt_id)?
|
||||||
.read()
|
.read()
|
||||||
.hints
|
.hints_by_id
|
||||||
.iter()
|
.get(&hint_id)
|
||||||
.find(|&(id, _)| id == &hint_id)
|
|
||||||
.map(|(_, hint)| hint)
|
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -500,7 +501,13 @@ impl InlayHintCache {
|
||||||
let mut hints = Vec::new();
|
let mut hints = Vec::new();
|
||||||
for excerpt_hints in self.hints.values() {
|
for excerpt_hints in self.hints.values() {
|
||||||
let excerpt_hints = excerpt_hints.read();
|
let excerpt_hints = excerpt_hints.read();
|
||||||
hints.extend(excerpt_hints.hints.iter().map(|(_, hint)| hint).cloned());
|
hints.extend(
|
||||||
|
excerpt_hints
|
||||||
|
.ordered_hints
|
||||||
|
.iter()
|
||||||
|
.map(|id| &excerpt_hints.hints_by_id[id])
|
||||||
|
.cloned(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
hints
|
hints
|
||||||
}
|
}
|
||||||
|
@ -518,12 +525,7 @@ impl InlayHintCache {
|
||||||
) {
|
) {
|
||||||
if let Some(excerpt_hints) = self.hints.get(&excerpt_id) {
|
if let Some(excerpt_hints) = self.hints.get(&excerpt_id) {
|
||||||
let mut guard = excerpt_hints.write();
|
let mut guard = excerpt_hints.write();
|
||||||
if let Some(cached_hint) = guard
|
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
||||||
.hints
|
|
||||||
.iter_mut()
|
|
||||||
.find(|(hint_id, _)| hint_id == &id)
|
|
||||||
.map(|(_, hint)| hint)
|
|
||||||
{
|
|
||||||
if let ResolveState::CanResolve(server_id, _) = &cached_hint.resolve_state {
|
if let ResolveState::CanResolve(server_id, _) = &cached_hint.resolve_state {
|
||||||
let hint_to_resolve = cached_hint.clone();
|
let hint_to_resolve = cached_hint.clone();
|
||||||
let server_id = *server_id;
|
let server_id = *server_id;
|
||||||
|
@ -555,12 +557,7 @@ impl InlayHintCache {
|
||||||
editor.inlay_hint_cache.hints.get(&excerpt_id)
|
editor.inlay_hint_cache.hints.get(&excerpt_id)
|
||||||
{
|
{
|
||||||
let mut guard = excerpt_hints.write();
|
let mut guard = excerpt_hints.write();
|
||||||
if let Some(cached_hint) = guard
|
if let Some(cached_hint) = guard.hints_by_id.get_mut(&id) {
|
||||||
.hints
|
|
||||||
.iter_mut()
|
|
||||||
.find(|(hint_id, _)| hint_id == &id)
|
|
||||||
.map(|(_, hint)| hint)
|
|
||||||
{
|
|
||||||
if cached_hint.resolve_state == ResolveState::Resolving {
|
if cached_hint.resolve_state == ResolveState::Resolving {
|
||||||
resolved_hint.resolve_state = ResolveState::Resolved;
|
resolved_hint.resolve_state = ResolveState::Resolved;
|
||||||
*cached_hint = resolved_hint;
|
*cached_hint = resolved_hint;
|
||||||
|
@ -986,12 +983,17 @@ fn calculate_hint_updates(
|
||||||
let missing_from_cache = match &cached_excerpt_hints {
|
let missing_from_cache = match &cached_excerpt_hints {
|
||||||
Some(cached_excerpt_hints) => {
|
Some(cached_excerpt_hints) => {
|
||||||
let cached_excerpt_hints = cached_excerpt_hints.read();
|
let cached_excerpt_hints = cached_excerpt_hints.read();
|
||||||
match cached_excerpt_hints.hints.binary_search_by(|probe| {
|
match cached_excerpt_hints
|
||||||
probe.1.position.cmp(&new_hint.position, buffer_snapshot)
|
.ordered_hints
|
||||||
}) {
|
.binary_search_by(|probe| {
|
||||||
|
cached_excerpt_hints.hints_by_id[probe]
|
||||||
|
.position
|
||||||
|
.cmp(&new_hint.position, buffer_snapshot)
|
||||||
|
}) {
|
||||||
Ok(ix) => {
|
Ok(ix) => {
|
||||||
let mut missing_from_cache = true;
|
let mut missing_from_cache = true;
|
||||||
for (cached_inlay_id, cached_hint) in &cached_excerpt_hints.hints[ix..] {
|
for id in &cached_excerpt_hints.ordered_hints[ix..] {
|
||||||
|
let cached_hint = &cached_excerpt_hints.hints_by_id[id];
|
||||||
if new_hint
|
if new_hint
|
||||||
.position
|
.position
|
||||||
.cmp(&cached_hint.position, buffer_snapshot)
|
.cmp(&cached_hint.position, buffer_snapshot)
|
||||||
|
@ -1000,7 +1002,7 @@ fn calculate_hint_updates(
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if cached_hint == &new_hint {
|
if cached_hint == &new_hint {
|
||||||
excerpt_hints_to_persist.insert(*cached_inlay_id, cached_hint.kind);
|
excerpt_hints_to_persist.insert(*id, cached_hint.kind);
|
||||||
missing_from_cache = false;
|
missing_from_cache = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1031,12 +1033,12 @@ fn calculate_hint_updates(
|
||||||
let cached_excerpt_hints = cached_excerpt_hints.read();
|
let cached_excerpt_hints = cached_excerpt_hints.read();
|
||||||
remove_from_cache.extend(
|
remove_from_cache.extend(
|
||||||
cached_excerpt_hints
|
cached_excerpt_hints
|
||||||
.hints
|
.ordered_hints
|
||||||
.iter()
|
.iter()
|
||||||
.filter(|(cached_inlay_id, _)| {
|
.filter(|cached_inlay_id| {
|
||||||
!excerpt_hints_to_persist.contains_key(cached_inlay_id)
|
!excerpt_hints_to_persist.contains_key(cached_inlay_id)
|
||||||
})
|
})
|
||||||
.map(|(cached_inlay_id, _)| *cached_inlay_id),
|
.copied(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1080,7 +1082,8 @@ fn apply_hint_update(
|
||||||
version: query.cache_version,
|
version: query.cache_version,
|
||||||
buffer_version: buffer_snapshot.version().clone(),
|
buffer_version: buffer_snapshot.version().clone(),
|
||||||
buffer_id: query.buffer_id,
|
buffer_id: query.buffer_id,
|
||||||
hints: Vec::new(),
|
ordered_hints: Vec::new(),
|
||||||
|
hints_by_id: HashMap::default(),
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
let mut cached_excerpt_hints = cached_excerpt_hints.write();
|
let mut cached_excerpt_hints = cached_excerpt_hints.write();
|
||||||
|
@ -1093,20 +1096,27 @@ fn apply_hint_update(
|
||||||
|
|
||||||
let mut cached_inlays_changed = !new_update.remove_from_cache.is_empty();
|
let mut cached_inlays_changed = !new_update.remove_from_cache.is_empty();
|
||||||
cached_excerpt_hints
|
cached_excerpt_hints
|
||||||
.hints
|
.ordered_hints
|
||||||
.retain(|(hint_id, _)| !new_update.remove_from_cache.contains(hint_id));
|
.retain(|hint_id| !new_update.remove_from_cache.contains(hint_id));
|
||||||
|
cached_excerpt_hints
|
||||||
|
.hints_by_id
|
||||||
|
.retain(|hint_id, _| !new_update.remove_from_cache.contains(hint_id));
|
||||||
let mut splice = InlaySplice {
|
let mut splice = InlaySplice {
|
||||||
to_remove: new_update.remove_from_visible,
|
to_remove: new_update.remove_from_visible,
|
||||||
to_insert: Vec::new(),
|
to_insert: Vec::new(),
|
||||||
};
|
};
|
||||||
for new_hint in new_update.add_to_cache {
|
for new_hint in new_update.add_to_cache {
|
||||||
let cached_hints = &mut cached_excerpt_hints.hints;
|
let insert_position = match cached_excerpt_hints
|
||||||
let insert_position = match cached_hints
|
.ordered_hints
|
||||||
.binary_search_by(|probe| probe.1.position.cmp(&new_hint.position, &buffer_snapshot))
|
.binary_search_by(|probe| {
|
||||||
{
|
cached_excerpt_hints.hints_by_id[probe]
|
||||||
|
.position
|
||||||
|
.cmp(&new_hint.position, &buffer_snapshot)
|
||||||
|
}) {
|
||||||
Ok(i) => {
|
Ok(i) => {
|
||||||
let mut insert_position = Some(i);
|
let mut insert_position = Some(i);
|
||||||
for (_, cached_hint) in &cached_hints[i..] {
|
for id in &cached_excerpt_hints.ordered_hints[i..] {
|
||||||
|
let cached_hint = &cached_excerpt_hints.hints_by_id[id];
|
||||||
if new_hint
|
if new_hint
|
||||||
.position
|
.position
|
||||||
.cmp(&cached_hint.position, &buffer_snapshot)
|
.cmp(&cached_hint.position, &buffer_snapshot)
|
||||||
|
@ -1137,7 +1147,11 @@ fn apply_hint_update(
|
||||||
.to_insert
|
.to_insert
|
||||||
.push(Inlay::hint(new_inlay_id, new_hint_position, &new_hint));
|
.push(Inlay::hint(new_inlay_id, new_hint_position, &new_hint));
|
||||||
}
|
}
|
||||||
cached_hints.insert(insert_position, (InlayId::Hint(new_inlay_id), new_hint));
|
let new_id = InlayId::Hint(new_inlay_id);
|
||||||
|
cached_excerpt_hints.hints_by_id.insert(new_id, new_hint);
|
||||||
|
cached_excerpt_hints
|
||||||
|
.ordered_hints
|
||||||
|
.insert(insert_position, new_id);
|
||||||
cached_inlays_changed = true;
|
cached_inlays_changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1157,7 +1171,7 @@ fn apply_hint_update(
|
||||||
outdated_excerpt_caches.insert(*excerpt_id);
|
outdated_excerpt_caches.insert(*excerpt_id);
|
||||||
splice
|
splice
|
||||||
.to_remove
|
.to_remove
|
||||||
.extend(excerpt_hints.hints.iter().map(|(id, _)| id));
|
.extend(excerpt_hints.ordered_hints.iter().copied());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cached_inlays_changed |= !outdated_excerpt_caches.is_empty();
|
cached_inlays_changed |= !outdated_excerpt_caches.is_empty();
|
||||||
|
@ -3311,8 +3325,9 @@ all hints should be invalidated and requeried for all of its visible excerpts"
|
||||||
pub fn cached_hint_labels(editor: &Editor) -> Vec<String> {
|
pub fn cached_hint_labels(editor: &Editor) -> Vec<String> {
|
||||||
let mut labels = Vec::new();
|
let mut labels = Vec::new();
|
||||||
for (_, excerpt_hints) in &editor.inlay_hint_cache().hints {
|
for (_, excerpt_hints) in &editor.inlay_hint_cache().hints {
|
||||||
for (_, inlay) in &excerpt_hints.read().hints {
|
let excerpt_hints = excerpt_hints.read();
|
||||||
labels.push(inlay.text());
|
for id in &excerpt_hints.ordered_hints {
|
||||||
|
labels.push(excerpt_hints.hints_by_id[id].text());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
display_map::{DisplaySnapshot, InlayOffset},
|
display_map::DisplaySnapshot,
|
||||||
element::PointForPosition,
|
element::PointForPosition,
|
||||||
hover_popover::{self, InlayHover},
|
hover_popover::{self, InlayHover},
|
||||||
Anchor, DisplayPoint, Editor, EditorSnapshot, SelectPhase,
|
Anchor, DisplayPoint, Editor, EditorSnapshot, InlayId, SelectPhase,
|
||||||
};
|
};
|
||||||
use gpui::{Task, ViewContext};
|
use gpui::{Task, ViewContext};
|
||||||
use language::{Bias, ToOffset};
|
use language::{Bias, ToOffset};
|
||||||
|
@ -17,44 +17,19 @@ 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<DocumentRange>,
|
pub symbol_range: Option<RangeInEditor>,
|
||||||
pub kind: Option<LinkDefinitionKind>,
|
pub kind: Option<LinkDefinitionKind>,
|
||||||
pub definitions: Vec<GoToDefinitionLink>,
|
pub definitions: Vec<GoToDefinitionLink>,
|
||||||
pub task: Option<Task<Option<()>>>,
|
pub task: Option<Task<Option<()>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Eq, PartialEq, Clone)]
|
||||||
pub enum GoToDefinitionTrigger {
|
pub enum RangeInEditor {
|
||||||
Text(DisplayPoint),
|
|
||||||
InlayHint(InlayRange, lsp::Location, LanguageServerId),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum GoToDefinitionLink {
|
|
||||||
Text(LocationLink),
|
|
||||||
InlayHint(lsp::Location, LanguageServerId),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub struct InlayRange {
|
|
||||||
pub inlay_position: Anchor,
|
|
||||||
pub highlight_start: InlayOffset,
|
|
||||||
pub highlight_end: InlayOffset,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum TriggerPoint {
|
|
||||||
Text(Anchor),
|
|
||||||
InlayHint(InlayRange, lsp::Location, LanguageServerId),
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
||||||
pub enum DocumentRange {
|
|
||||||
Text(Range<Anchor>),
|
Text(Range<Anchor>),
|
||||||
Inlay(InlayRange),
|
Inlay(InlayHighlight),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DocumentRange {
|
impl RangeInEditor {
|
||||||
pub fn as_text_range(&self) -> Option<Range<Anchor>> {
|
pub fn as_text_range(&self) -> Option<Range<Anchor>> {
|
||||||
match self {
|
match self {
|
||||||
Self::Text(range) => Some(range.clone()),
|
Self::Text(range) => Some(range.clone()),
|
||||||
|
@ -64,28 +39,47 @@ 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) {
|
||||||
(DocumentRange::Text(range), TriggerPoint::Text(point)) => {
|
(Self::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()
|
||||||
}
|
}
|
||||||
(DocumentRange::Inlay(range), TriggerPoint::InlayHint(point, _, _)) => {
|
(Self::Inlay(highlight), TriggerPoint::InlayHint(point, _, _)) => {
|
||||||
range.highlight_start.cmp(&point.highlight_end).is_le()
|
highlight.inlay == point.inlay
|
||||||
&& range.highlight_end.cmp(&point.highlight_end).is_ge()
|
&& highlight.range.contains(&point.range.start)
|
||||||
|
&& highlight.range.contains(&point.range.end)
|
||||||
}
|
}
|
||||||
(DocumentRange::Inlay(_), TriggerPoint::Text(_))
|
(Self::Inlay(_), TriggerPoint::Text(_))
|
||||||
| (DocumentRange::Text(_), TriggerPoint::InlayHint(_, _, _)) => false,
|
| (Self::Text(_), TriggerPoint::InlayHint(_, _, _)) => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TriggerPoint {
|
#[derive(Debug)]
|
||||||
fn anchor(&self) -> &Anchor {
|
pub enum GoToDefinitionTrigger {
|
||||||
match self {
|
Text(DisplayPoint),
|
||||||
TriggerPoint::Text(anchor) => anchor,
|
InlayHint(InlayHighlight, lsp::Location, LanguageServerId),
|
||||||
TriggerPoint::InlayHint(range, _, _) => &range.inlay_position,
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum GoToDefinitionLink {
|
||||||
|
Text(LocationLink),
|
||||||
|
InlayHint(lsp::Location, LanguageServerId),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct InlayHighlight {
|
||||||
|
pub inlay: InlayId,
|
||||||
|
pub inlay_position: Anchor,
|
||||||
|
pub range: Range<usize>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub enum TriggerPoint {
|
||||||
|
Text(Anchor),
|
||||||
|
InlayHint(InlayHighlight, lsp::Location, LanguageServerId),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TriggerPoint {
|
||||||
pub fn definition_kind(&self, shift: bool) -> LinkDefinitionKind {
|
pub fn definition_kind(&self, shift: bool) -> LinkDefinitionKind {
|
||||||
match self {
|
match self {
|
||||||
TriggerPoint::Text(_) => {
|
TriggerPoint::Text(_) => {
|
||||||
|
@ -98,6 +92,13 @@ impl TriggerPoint {
|
||||||
TriggerPoint::InlayHint(_, _, _) => LinkDefinitionKind::Type,
|
TriggerPoint::InlayHint(_, _, _) => LinkDefinitionKind::Type,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn anchor(&self) -> &Anchor {
|
||||||
|
match self {
|
||||||
|
TriggerPoint::Text(anchor) => anchor,
|
||||||
|
TriggerPoint::InlayHint(inlay_range, _, _) => &inlay_range.inlay_position,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_go_to_definition_link(
|
pub fn update_go_to_definition_link(
|
||||||
|
@ -135,11 +136,7 @@ pub fn update_go_to_definition_link(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(TriggerPoint::InlayHint(range_a, _, _), TriggerPoint::InlayHint(range_b, _, _)) => {
|
(TriggerPoint::InlayHint(range_a, _, _), TriggerPoint::InlayHint(range_b, _, _)) => {
|
||||||
if range_a
|
if range_a == range_b {
|
||||||
.inlay_position
|
|
||||||
.cmp(&range_b.inlay_position, &snapshot.buffer_snapshot)
|
|
||||||
.is_eq()
|
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,10 +170,6 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
shift_held: bool,
|
shift_held: bool,
|
||||||
cx: &mut ViewContext<'_, '_, Editor>,
|
cx: &mut ViewContext<'_, '_, Editor>,
|
||||||
) {
|
) {
|
||||||
let hint_start_offset =
|
|
||||||
snapshot.display_point_to_inlay_offset(point_for_position.previous_valid, Bias::Left);
|
|
||||||
let hint_end_offset =
|
|
||||||
snapshot.display_point_to_inlay_offset(point_for_position.next_valid, Bias::Right);
|
|
||||||
let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
|
let hovered_offset = if point_for_position.column_overshoot_after_line_end == 0 {
|
||||||
Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
|
Some(snapshot.display_point_to_inlay_offset(point_for_position.exact_unclipped, Bias::Left))
|
||||||
} else {
|
} else {
|
||||||
|
@ -224,15 +217,14 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ResolveState::Resolved => {
|
ResolveState::Resolved => {
|
||||||
let mut actual_hint_start = hint_start_offset;
|
let mut extra_shift_left = 0;
|
||||||
let mut actual_hint_end = hint_end_offset;
|
let mut extra_shift_right = 0;
|
||||||
if cached_hint.padding_left {
|
if cached_hint.padding_left {
|
||||||
actual_hint_start.0 += 1;
|
extra_shift_left += 1;
|
||||||
actual_hint_end.0 += 1;
|
extra_shift_right += 1;
|
||||||
}
|
}
|
||||||
if cached_hint.padding_right {
|
if cached_hint.padding_right {
|
||||||
actual_hint_start.0 += 1;
|
extra_shift_right += 1;
|
||||||
actual_hint_end.0 += 1;
|
|
||||||
}
|
}
|
||||||
match cached_hint.label {
|
match cached_hint.label {
|
||||||
project::InlayHintLabel::String(_) => {
|
project::InlayHintLabel::String(_) => {
|
||||||
|
@ -253,11 +245,11 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
triggered_from: hovered_offset,
|
range: InlayHighlight {
|
||||||
range: InlayRange {
|
inlay: hovered_hint.id,
|
||||||
inlay_position: hovered_hint.position,
|
inlay_position: hovered_hint.position,
|
||||||
highlight_start: actual_hint_start,
|
range: extra_shift_left
|
||||||
highlight_end: actual_hint_end,
|
..hovered_hint.text.len() + extra_shift_right,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
|
@ -266,13 +258,24 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
project::InlayHintLabel::LabelParts(label_parts) => {
|
project::InlayHintLabel::LabelParts(label_parts) => {
|
||||||
|
let hint_start =
|
||||||
|
snapshot.anchor_to_inlay_offset(hovered_hint.position);
|
||||||
if let Some((hovered_hint_part, part_range)) =
|
if let Some((hovered_hint_part, part_range)) =
|
||||||
hover_popover::find_hovered_hint_part(
|
hover_popover::find_hovered_hint_part(
|
||||||
label_parts,
|
label_parts,
|
||||||
actual_hint_start..actual_hint_end,
|
hint_start,
|
||||||
hovered_offset,
|
hovered_offset,
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
let highlight_start =
|
||||||
|
(part_range.start - hint_start).0 + extra_shift_left;
|
||||||
|
let highlight_end =
|
||||||
|
(part_range.end - hint_start).0 + extra_shift_right;
|
||||||
|
let highlight = InlayHighlight {
|
||||||
|
inlay: hovered_hint.id,
|
||||||
|
inlay_position: hovered_hint.position,
|
||||||
|
range: highlight_start..highlight_end,
|
||||||
|
};
|
||||||
if let Some(tooltip) = hovered_hint_part.tooltip {
|
if let Some(tooltip) = hovered_hint_part.tooltip {
|
||||||
hover_popover::hover_at_inlay(
|
hover_popover::hover_at_inlay(
|
||||||
editor,
|
editor,
|
||||||
|
@ -292,12 +295,7 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
kind: content.kind,
|
kind: content.kind,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
triggered_from: hovered_offset,
|
range: highlight.clone(),
|
||||||
range: InlayRange {
|
|
||||||
inlay_position: hovered_hint.position,
|
|
||||||
highlight_start: part_range.start,
|
|
||||||
highlight_end: part_range.end,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
@ -310,11 +308,7 @@ pub fn update_inlay_link_and_hover_points(
|
||||||
update_go_to_definition_link(
|
update_go_to_definition_link(
|
||||||
editor,
|
editor,
|
||||||
Some(GoToDefinitionTrigger::InlayHint(
|
Some(GoToDefinitionTrigger::InlayHint(
|
||||||
InlayRange {
|
highlight,
|
||||||
inlay_position: hovered_hint.position,
|
|
||||||
highlight_start: part_range.start,
|
|
||||||
highlight_end: part_range.end,
|
|
||||||
},
|
|
||||||
location,
|
location,
|
||||||
language_server_id,
|
language_server_id,
|
||||||
)),
|
)),
|
||||||
|
@ -425,7 +419,7 @@ pub fn show_link_definition(
|
||||||
let end = snapshot
|
let end = snapshot
|
||||||
.buffer_snapshot
|
.buffer_snapshot
|
||||||
.anchor_in_excerpt(excerpt_id.clone(), origin.range.end);
|
.anchor_in_excerpt(excerpt_id.clone(), origin.range.end);
|
||||||
DocumentRange::Text(start..end)
|
RangeInEditor::Text(start..end)
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
definition_result
|
definition_result
|
||||||
|
@ -435,8 +429,8 @@ pub fn show_link_definition(
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
TriggerPoint::InlayHint(trigger_source, lsp_location, server_id) => Some((
|
TriggerPoint::InlayHint(highlight, lsp_location, server_id) => Some((
|
||||||
Some(DocumentRange::Inlay(*trigger_source)),
|
Some(RangeInEditor::Inlay(highlight.clone())),
|
||||||
vec![GoToDefinitionLink::InlayHint(
|
vec![GoToDefinitionLink::InlayHint(
|
||||||
lsp_location.clone(),
|
lsp_location.clone(),
|
||||||
*server_id,
|
*server_id,
|
||||||
|
@ -446,7 +440,7 @@ pub fn show_link_definition(
|
||||||
|
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
// Clear any existing highlights
|
// Clear any existing highlights
|
||||||
this.clear_text_highlights::<LinkGoToDefinitionState>(cx);
|
this.clear_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()
|
||||||
|
@ -498,26 +492,26 @@ pub fn show_link_definition(
|
||||||
// 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, _) =
|
let (offset_range, _) =
|
||||||
snapshot.surrounding_word(*trigger_anchor);
|
snapshot.surrounding_word(*trigger_anchor);
|
||||||
DocumentRange::Text(
|
RangeInEditor::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(highlight, _, _) => {
|
||||||
DocumentRange::Inlay(*inlay_coordinates)
|
RangeInEditor::Inlay(highlight.clone())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
match highlight_range {
|
match highlight_range {
|
||||||
DocumentRange::Text(text_range) => this
|
RangeInEditor::Text(text_range) => this
|
||||||
.highlight_text::<LinkGoToDefinitionState>(
|
.highlight_text::<LinkGoToDefinitionState>(
|
||||||
vec![text_range],
|
vec![text_range],
|
||||||
style,
|
style,
|
||||||
cx,
|
cx,
|
||||||
),
|
),
|
||||||
DocumentRange::Inlay(inlay_coordinates) => this
|
RangeInEditor::Inlay(highlight) => this
|
||||||
.highlight_inlays::<LinkGoToDefinitionState>(
|
.highlight_inlays::<LinkGoToDefinitionState>(
|
||||||
vec![inlay_coordinates],
|
vec![highlight],
|
||||||
style,
|
style,
|
||||||
cx,
|
cx,
|
||||||
),
|
),
|
||||||
|
@ -547,7 +541,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_text_highlights::<LinkGoToDefinitionState>(cx);
|
editor.clear_highlights::<LinkGoToDefinitionState>(cx);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn go_to_fetched_definition(
|
pub fn go_to_fetched_definition(
|
||||||
|
@ -1199,30 +1193,19 @@ mod tests {
|
||||||
cx.foreground().run_until_parked();
|
cx.foreground().run_until_parked();
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
let snapshot = editor.snapshot(cx);
|
let snapshot = editor.snapshot(cx);
|
||||||
let actual_ranges = snapshot
|
let actual_highlights = snapshot
|
||||||
.highlight_ranges::<LinkGoToDefinitionState>()
|
.inlay_highlights::<LinkGoToDefinitionState>()
|
||||||
.map(|ranges| ranges.as_ref().clone().1)
|
|
||||||
.unwrap_or_default()
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|range| match range {
|
.flat_map(|highlights| highlights.values().map(|(_, highlight)| highlight))
|
||||||
DocumentRange::Text(range) => {
|
|
||||||
panic!("Unexpected regular text selection range {range:?}")
|
|
||||||
}
|
|
||||||
DocumentRange::Inlay(inlay_range) => inlay_range,
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
let buffer_snapshot = editor.buffer().update(cx, |buffer, cx| buffer.snapshot(cx));
|
let buffer_snapshot = editor.buffer().update(cx, |buffer, cx| buffer.snapshot(cx));
|
||||||
let expected_highlight_start = snapshot.display_point_to_inlay_offset(
|
let expected_highlight = InlayHighlight {
|
||||||
inlay_range.start.to_display_point(&snapshot),
|
inlay: InlayId::Hint(0),
|
||||||
Bias::Left,
|
|
||||||
);
|
|
||||||
let expected_ranges = vec![InlayRange {
|
|
||||||
inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right),
|
inlay_position: buffer_snapshot.anchor_at(inlay_range.start, Bias::Right),
|
||||||
highlight_start: expected_highlight_start,
|
range: 0..hint_label.len(),
|
||||||
highlight_end: InlayOffset(expected_highlight_start.0 + hint_label.len()),
|
};
|
||||||
}];
|
assert_set_eq!(actual_highlights, vec![&expected_highlight]);
|
||||||
assert_set_eq!(actual_ranges, expected_ranges);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Unpress cmd causes highlight to go away
|
// Unpress cmd causes highlight to go away
|
||||||
|
@ -1242,17 +1225,9 @@ mod tests {
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
let snapshot = editor.snapshot(cx);
|
let snapshot = editor.snapshot(cx);
|
||||||
let actual_ranges = snapshot
|
let actual_ranges = snapshot
|
||||||
.highlight_ranges::<LinkGoToDefinitionState>()
|
.text_highlight_ranges::<LinkGoToDefinitionState>()
|
||||||
.map(|ranges| ranges.as_ref().clone().1)
|
.map(|ranges| ranges.as_ref().clone().1)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default();
|
||||||
.into_iter()
|
|
||||||
.map(|range| match range {
|
|
||||||
DocumentRange::Text(range) => {
|
|
||||||
panic!("Unexpected regular text selection range {range:?}")
|
|
||||||
}
|
|
||||||
DocumentRange::Inlay(inlay_range) => inlay_range,
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
assert!(actual_ranges.is_empty(), "When no cmd is pressed, should have no hint label selected, but got: {actual_ranges:?}");
|
assert!(actual_ranges.is_empty(), "When no cmd is pressed, should have no hint label selected, but got: {actual_ranges:?}");
|
||||||
});
|
});
|
||||||
|
|
|
@ -225,7 +225,6 @@ impl<'a> EditorTestContext<'a> {
|
||||||
.map(|h| h.1.clone())
|
.map(|h| h.1.clone())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|range| range.as_text_range())
|
|
||||||
.map(|range| range.to_offset(&snapshot.buffer_snapshot))
|
.map(|range| range.to_offset(&snapshot.buffer_snapshot))
|
||||||
.collect()
|
.collect()
|
||||||
});
|
});
|
||||||
|
@ -237,11 +236,10 @@ impl<'a> EditorTestContext<'a> {
|
||||||
let expected_ranges = self.ranges(marked_text);
|
let expected_ranges = self.ranges(marked_text);
|
||||||
let snapshot = self.update_editor(|editor, cx| editor.snapshot(cx));
|
let snapshot = self.update_editor(|editor, cx| editor.snapshot(cx));
|
||||||
let actual_ranges: Vec<Range<usize>> = snapshot
|
let actual_ranges: Vec<Range<usize>> = snapshot
|
||||||
.highlight_ranges::<Tag>()
|
.text_highlight_ranges::<Tag>()
|
||||||
.map(|ranges| ranges.as_ref().clone().1)
|
.map(|ranges| ranges.as_ref().clone().1)
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|range| range.as_text_range())
|
|
||||||
.map(|range| range.to_offset(&snapshot.buffer_snapshot))
|
.map(|range| range.to_offset(&snapshot.buffer_snapshot))
|
||||||
.collect();
|
.collect();
|
||||||
assert_set_eq!(actual_ranges, expected_ranges);
|
assert_set_eq!(actual_ranges, expected_ranges);
|
||||||
|
|
|
@ -75,7 +75,6 @@ impl KeymapMatcher {
|
||||||
keystroke: Keystroke,
|
keystroke: Keystroke,
|
||||||
mut dispatch_path: Vec<(usize, KeymapContext)>,
|
mut dispatch_path: Vec<(usize, KeymapContext)>,
|
||||||
) -> MatchResult {
|
) -> MatchResult {
|
||||||
let mut any_pending = false;
|
|
||||||
// Collect matched bindings into an ordered list using the position in the matching binding first,
|
// Collect matched bindings into an ordered list using the position in the matching binding first,
|
||||||
// and then the order the binding matched in the view tree second.
|
// and then the order the binding matched in the view tree second.
|
||||||
// The key is the reverse position of the binding in the bindings list so that later bindings
|
// The key is the reverse position of the binding in the bindings list so that later bindings
|
||||||
|
@ -84,7 +83,8 @@ impl KeymapMatcher {
|
||||||
let no_action_id = (NoAction {}).id();
|
let no_action_id = (NoAction {}).id();
|
||||||
|
|
||||||
let first_keystroke = self.pending_keystrokes.is_empty();
|
let first_keystroke = self.pending_keystrokes.is_empty();
|
||||||
self.pending_keystrokes.push(keystroke.clone());
|
let mut pending_key = None;
|
||||||
|
let mut previous_keystrokes = self.pending_keystrokes.clone();
|
||||||
|
|
||||||
self.contexts.clear();
|
self.contexts.clear();
|
||||||
self.contexts
|
self.contexts
|
||||||
|
@ -106,24 +106,32 @@ impl KeymapMatcher {
|
||||||
}
|
}
|
||||||
|
|
||||||
for binding in self.keymap.bindings().iter().rev() {
|
for binding in self.keymap.bindings().iter().rev() {
|
||||||
match binding.match_keys_and_context(&self.pending_keystrokes, &self.contexts[i..])
|
for possibility in keystroke.match_possibilities() {
|
||||||
{
|
previous_keystrokes.push(possibility.clone());
|
||||||
BindingMatchResult::Complete(action) => {
|
match binding.match_keys_and_context(&previous_keystrokes, &self.contexts[i..])
|
||||||
if action.id() != no_action_id {
|
{
|
||||||
matched_bindings.push((*view_id, action));
|
BindingMatchResult::Complete(action) => {
|
||||||
|
if action.id() != no_action_id {
|
||||||
|
matched_bindings.push((*view_id, action));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BindingMatchResult::Partial => {
|
||||||
|
if pending_key == None || pending_key == Some(possibility.clone()) {
|
||||||
|
self.pending_views
|
||||||
|
.insert(*view_id, self.contexts[i].clone());
|
||||||
|
pending_key = Some(possibility)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
BindingMatchResult::Partial => {
|
previous_keystrokes.pop();
|
||||||
self.pending_views
|
|
||||||
.insert(*view_id, self.contexts[i].clone());
|
|
||||||
any_pending = true;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !any_pending {
|
if pending_key.is_some() {
|
||||||
|
self.pending_keystrokes.push(pending_key.unwrap());
|
||||||
|
} else {
|
||||||
self.clear_pending();
|
self.clear_pending();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,7 +139,7 @@ impl KeymapMatcher {
|
||||||
// Collect the sorted matched bindings into the final vec for ease of use
|
// Collect the sorted matched bindings into the final vec for ease of use
|
||||||
// Matched bindings are in order by precedence
|
// Matched bindings are in order by precedence
|
||||||
MatchResult::Matches(matched_bindings)
|
MatchResult::Matches(matched_bindings)
|
||||||
} else if any_pending {
|
} else if !self.pending_keystrokes.is_empty() {
|
||||||
MatchResult::Pending
|
MatchResult::Pending
|
||||||
} else {
|
} else {
|
||||||
MatchResult::None
|
MatchResult::None
|
||||||
|
@ -340,6 +348,7 @@ mod tests {
|
||||||
shift: false,
|
shift: false,
|
||||||
cmd: false,
|
cmd: false,
|
||||||
function: false,
|
function: false,
|
||||||
|
ime_key: None,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -352,6 +361,7 @@ mod tests {
|
||||||
shift: true,
|
shift: true,
|
||||||
cmd: false,
|
cmd: false,
|
||||||
function: false,
|
function: false,
|
||||||
|
ime_key: None,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -364,6 +374,7 @@ mod tests {
|
||||||
shift: true,
|
shift: true,
|
||||||
cmd: true,
|
cmd: true,
|
||||||
function: false,
|
function: false,
|
||||||
|
ime_key: None,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -466,7 +477,7 @@ mod tests {
|
||||||
#[derive(Clone, Deserialize, PartialEq, Eq, Debug)]
|
#[derive(Clone, Deserialize, PartialEq, Eq, Debug)]
|
||||||
pub struct A(pub String);
|
pub struct A(pub String);
|
||||||
impl_actions!(test, [A]);
|
impl_actions!(test, [A]);
|
||||||
actions!(test, [B, Ab]);
|
actions!(test, [B, Ab, Dollar, Quote, Ess, Backtick]);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq)]
|
#[derive(Clone, Debug, Eq, PartialEq)]
|
||||||
struct ActionArg {
|
struct ActionArg {
|
||||||
|
@ -477,6 +488,10 @@ mod tests {
|
||||||
Binding::new("a", A("x".to_string()), Some("a")),
|
Binding::new("a", A("x".to_string()), Some("a")),
|
||||||
Binding::new("b", B, Some("a")),
|
Binding::new("b", B, Some("a")),
|
||||||
Binding::new("a b", Ab, Some("a || b")),
|
Binding::new("a b", Ab, Some("a || b")),
|
||||||
|
Binding::new("$", Dollar, Some("a")),
|
||||||
|
Binding::new("\"", Quote, Some("a")),
|
||||||
|
Binding::new("alt-s", Ess, Some("a")),
|
||||||
|
Binding::new("ctrl-`", Backtick, Some("a")),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
let mut context_a = KeymapContext::default();
|
let mut context_a = KeymapContext::default();
|
||||||
|
@ -543,6 +558,30 @@ mod tests {
|
||||||
MatchResult::Matches(vec![(1, Box::new(Ab))])
|
MatchResult::Matches(vec![(1, Box::new(Ab))])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// handle Czech $ (option + 4 key)
|
||||||
|
assert_eq!(
|
||||||
|
matcher.push_keystroke(Keystroke::parse("alt-ç->$")?, vec![(1, context_a.clone())]),
|
||||||
|
MatchResult::Matches(vec![(1, Box::new(Dollar))])
|
||||||
|
);
|
||||||
|
|
||||||
|
// handle Brazillian quote (quote key then space key)
|
||||||
|
assert_eq!(
|
||||||
|
matcher.push_keystroke(Keystroke::parse("space->\"")?, vec![(1, context_a.clone())]),
|
||||||
|
MatchResult::Matches(vec![(1, Box::new(Quote))])
|
||||||
|
);
|
||||||
|
|
||||||
|
// handle ctrl+` on a brazillian keyboard
|
||||||
|
assert_eq!(
|
||||||
|
matcher.push_keystroke(Keystroke::parse("ctrl-->`")?, vec![(1, context_a.clone())]),
|
||||||
|
MatchResult::Matches(vec![(1, Box::new(Backtick))])
|
||||||
|
);
|
||||||
|
|
||||||
|
// handle alt-s on a US keyboard
|
||||||
|
assert_eq!(
|
||||||
|
matcher.push_keystroke(Keystroke::parse("alt-s->ß")?, vec![(1, context_a.clone())]),
|
||||||
|
MatchResult::Matches(vec![(1, Box::new(Ess))])
|
||||||
|
);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -162,7 +162,8 @@ mod tests {
|
||||||
shift: false,
|
shift: false,
|
||||||
cmd: false,
|
cmd: false,
|
||||||
function: false,
|
function: false,
|
||||||
key: "q".to_string()
|
key: "q".to_string(),
|
||||||
|
ime_key: None,
|
||||||
}],
|
}],
|
||||||
"{keystroke_duplicate_to_1:?} should have the expected keystroke in the keymap"
|
"{keystroke_duplicate_to_1:?} should have the expected keystroke in the keymap"
|
||||||
);
|
);
|
||||||
|
@ -179,7 +180,8 @@ mod tests {
|
||||||
shift: false,
|
shift: false,
|
||||||
cmd: false,
|
cmd: false,
|
||||||
function: false,
|
function: false,
|
||||||
key: "w".to_string()
|
key: "w".to_string(),
|
||||||
|
ime_key: None,
|
||||||
},
|
},
|
||||||
&Keystroke {
|
&Keystroke {
|
||||||
ctrl: true,
|
ctrl: true,
|
||||||
|
@ -187,7 +189,8 @@ mod tests {
|
||||||
shift: false,
|
shift: false,
|
||||||
cmd: false,
|
cmd: false,
|
||||||
function: false,
|
function: false,
|
||||||
key: "w".to_string()
|
key: "w".to_string(),
|
||||||
|
ime_key: None,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"{full_duplicate_to_2:?} should have a duplicated keystroke in the keymap"
|
"{full_duplicate_to_2:?} should have a duplicated keystroke in the keymap"
|
||||||
|
@ -339,7 +342,8 @@ mod tests {
|
||||||
shift: false,
|
shift: false,
|
||||||
cmd: false,
|
cmd: false,
|
||||||
function: false,
|
function: false,
|
||||||
key: expected_key.to_string()
|
key: expected_key.to_string(),
|
||||||
|
ime_key: None,
|
||||||
}],
|
}],
|
||||||
"{expected:?} should have the expected keystroke with key '{expected_key}' in the keymap for element {i}"
|
"{expected:?} should have the expected keystroke with key '{expected_key}' in the keymap for element {i}"
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,6 +2,7 @@ use std::fmt::Write;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Eq, PartialEq, Default, Deserialize, Hash)]
|
#[derive(Clone, Debug, Eq, PartialEq, Default, Deserialize, Hash)]
|
||||||
pub struct Keystroke {
|
pub struct Keystroke {
|
||||||
|
@ -10,10 +11,47 @@ pub struct Keystroke {
|
||||||
pub shift: bool,
|
pub shift: bool,
|
||||||
pub cmd: bool,
|
pub cmd: bool,
|
||||||
pub function: bool,
|
pub function: bool,
|
||||||
|
/// key is the character printed on the key that was pressed
|
||||||
|
/// e.g. for option-s, key is "s"
|
||||||
pub key: String,
|
pub key: String,
|
||||||
|
/// ime_key is the character inserted by the IME engine when that key was pressed.
|
||||||
|
/// e.g. for option-s, ime_key is "ß"
|
||||||
|
pub ime_key: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Keystroke {
|
impl Keystroke {
|
||||||
|
// When matching a key we cannot know whether the user intended to type
|
||||||
|
// the ime_key or the key. On some non-US keyboards keys we use in our
|
||||||
|
// bindings are behind option (for example `$` is typed `alt-ç` on a Czech keyboard),
|
||||||
|
// and on some keyboards the IME handler converts a sequence of keys into a
|
||||||
|
// specific character (for example `"` is typed as `" space` on a brazillian keyboard).
|
||||||
|
pub fn match_possibilities(&self) -> SmallVec<[Keystroke; 2]> {
|
||||||
|
let mut possibilities = SmallVec::new();
|
||||||
|
match self.ime_key.as_ref() {
|
||||||
|
None => possibilities.push(self.clone()),
|
||||||
|
Some(ime_key) => {
|
||||||
|
possibilities.push(Keystroke {
|
||||||
|
ctrl: self.ctrl,
|
||||||
|
alt: false,
|
||||||
|
shift: false,
|
||||||
|
cmd: false,
|
||||||
|
function: false,
|
||||||
|
key: ime_key.to_string(),
|
||||||
|
ime_key: None,
|
||||||
|
});
|
||||||
|
possibilities.push(Keystroke {
|
||||||
|
ime_key: None,
|
||||||
|
..self.clone()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
possibilities
|
||||||
|
}
|
||||||
|
|
||||||
|
/// key syntax is:
|
||||||
|
/// [ctrl-][alt-][shift-][cmd-][fn-]key[->ime_key]
|
||||||
|
/// ime_key is only used for generating test events,
|
||||||
|
/// when matching a key with an ime_key set will be matched without it.
|
||||||
pub fn parse(source: &str) -> anyhow::Result<Self> {
|
pub fn parse(source: &str) -> anyhow::Result<Self> {
|
||||||
let mut ctrl = false;
|
let mut ctrl = false;
|
||||||
let mut alt = false;
|
let mut alt = false;
|
||||||
|
@ -21,6 +59,7 @@ impl Keystroke {
|
||||||
let mut cmd = false;
|
let mut cmd = false;
|
||||||
let mut function = false;
|
let mut function = false;
|
||||||
let mut key = None;
|
let mut key = None;
|
||||||
|
let mut ime_key = None;
|
||||||
|
|
||||||
let mut components = source.split('-').peekable();
|
let mut components = source.split('-').peekable();
|
||||||
while let Some(component) = components.next() {
|
while let Some(component) = components.next() {
|
||||||
|
@ -31,10 +70,14 @@ impl Keystroke {
|
||||||
"cmd" => cmd = true,
|
"cmd" => cmd = true,
|
||||||
"fn" => function = true,
|
"fn" => function = true,
|
||||||
_ => {
|
_ => {
|
||||||
if let Some(component) = components.peek() {
|
if let Some(next) = components.peek() {
|
||||||
if component.is_empty() && source.ends_with('-') {
|
if next.is_empty() && source.ends_with('-') {
|
||||||
key = Some(String::from("-"));
|
key = Some(String::from("-"));
|
||||||
break;
|
break;
|
||||||
|
} else if next.len() > 1 && next.starts_with('>') {
|
||||||
|
key = Some(String::from(component));
|
||||||
|
ime_key = Some(String::from(&next[1..]));
|
||||||
|
components.next();
|
||||||
} else {
|
} else {
|
||||||
return Err(anyhow!("Invalid keystroke `{}`", source));
|
return Err(anyhow!("Invalid keystroke `{}`", source));
|
||||||
}
|
}
|
||||||
|
@ -54,6 +97,7 @@ impl Keystroke {
|
||||||
cmd,
|
cmd,
|
||||||
function,
|
function,
|
||||||
key,
|
key,
|
||||||
|
ime_key,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -327,6 +327,7 @@ unsafe fn parse_keystroke(native_event: id) -> Keystroke {
|
||||||
cmd,
|
cmd,
|
||||||
function,
|
function,
|
||||||
key,
|
key,
|
||||||
|
ime_key: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,6 +285,7 @@ enum ImeState {
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
struct InsertText {
|
struct InsertText {
|
||||||
replacement_range: Option<Range<usize>>,
|
replacement_range: Option<Range<usize>>,
|
||||||
text: String,
|
text: String,
|
||||||
|
@ -1006,40 +1007,7 @@ extern "C" fn handle_key_event(this: &Object, native_event: id, key_equivalent:
|
||||||
.flatten()
|
.flatten()
|
||||||
.is_some();
|
.is_some();
|
||||||
if !is_composing {
|
if !is_composing {
|
||||||
// if the IME has changed the key, we'll first emit an event with the character
|
handled = callback(Event::KeyDown(event));
|
||||||
// generated by the IME system; then fallback to the keystroke if that is not
|
|
||||||
// handled.
|
|
||||||
// cases that we have working:
|
|
||||||
// - " on a brazillian layout by typing <quote><space>
|
|
||||||
// - ctrl-` on a brazillian layout by typing <ctrl-`>
|
|
||||||
// - $ on a czech QWERTY layout by typing <alt-4>
|
|
||||||
// - 4 on a czech QWERTY layout by typing <shift-4>
|
|
||||||
// - ctrl-4 on a czech QWERTY layout by typing <ctrl-alt-4> (or <ctrl-shift-4>)
|
|
||||||
if ime_text.is_some() && ime_text.as_ref() != Some(&event.keystroke.key) {
|
|
||||||
let event_with_ime_text = KeyDownEvent {
|
|
||||||
is_held: false,
|
|
||||||
keystroke: Keystroke {
|
|
||||||
// we match ctrl because some use-cases need it.
|
|
||||||
// we don't match alt because it's often used to generate the optional character
|
|
||||||
// we don't match shift because we're not here with letters (usually)
|
|
||||||
// we don't match cmd/fn because they don't seem to use IME
|
|
||||||
ctrl: event.keystroke.ctrl,
|
|
||||||
alt: false,
|
|
||||||
shift: false,
|
|
||||||
cmd: false,
|
|
||||||
function: false,
|
|
||||||
key: ime_text.clone().unwrap(),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
handled = callback(Event::KeyDown(event_with_ime_text));
|
|
||||||
}
|
|
||||||
if !handled {
|
|
||||||
// empty key happens when you type a deadkey in input composition.
|
|
||||||
// (e.g. on a brazillian keyboard typing quote is a deadkey)
|
|
||||||
if !event.keystroke.key.is_empty() {
|
|
||||||
handled = callback(Event::KeyDown(event));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !handled {
|
if !handled {
|
||||||
|
@ -1197,6 +1165,7 @@ extern "C" fn cancel_operation(this: &Object, _sel: Sel, _sender: id) {
|
||||||
shift: false,
|
shift: false,
|
||||||
function: false,
|
function: false,
|
||||||
key: ".".into(),
|
key: ".".into(),
|
||||||
|
ime_key: None,
|
||||||
};
|
};
|
||||||
let event = Event::KeyDown(KeyDownEvent {
|
let event = Event::KeyDown(KeyDownEvent {
|
||||||
keystroke: keystroke.clone(),
|
keystroke: keystroke.clone(),
|
||||||
|
@ -1479,6 +1448,9 @@ extern "C" fn insert_text(this: &Object, _: Sel, text: id, replacement_range: NS
|
||||||
replacement_range,
|
replacement_range,
|
||||||
text: text.to_string(),
|
text: text.to_string(),
|
||||||
});
|
});
|
||||||
|
if text.to_string().to_ascii_lowercase() != pending_key_down.0.keystroke.key {
|
||||||
|
pending_key_down.0.keystroke.ime_key = Some(text.to_string());
|
||||||
|
}
|
||||||
window_state.borrow_mut().pending_key_down = Some(pending_key_down);
|
window_state.borrow_mut().pending_key_down = Some(pending_key_down);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ pub fn init(cx: &mut AppContext) {
|
||||||
cx.add_action(BufferSearchBar::replace_all_on_pane);
|
cx.add_action(BufferSearchBar::replace_all_on_pane);
|
||||||
cx.add_action(BufferSearchBar::replace_next_on_pane);
|
cx.add_action(BufferSearchBar::replace_next_on_pane);
|
||||||
cx.add_action(BufferSearchBar::toggle_replace);
|
cx.add_action(BufferSearchBar::toggle_replace);
|
||||||
|
cx.add_action(BufferSearchBar::toggle_replace_on_a_pane);
|
||||||
add_toggle_option_action::<ToggleCaseSensitive>(SearchOptions::CASE_SENSITIVE, cx);
|
add_toggle_option_action::<ToggleCaseSensitive>(SearchOptions::CASE_SENSITIVE, cx);
|
||||||
add_toggle_option_action::<ToggleWholeWord>(SearchOptions::WHOLE_WORD, cx);
|
add_toggle_option_action::<ToggleWholeWord>(SearchOptions::WHOLE_WORD, cx);
|
||||||
}
|
}
|
||||||
|
@ -889,6 +890,21 @@ impl BufferSearchBar {
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
fn toggle_replace_on_a_pane(pane: &mut Pane, _: &ToggleReplace, cx: &mut ViewContext<Pane>) {
|
||||||
|
let mut should_propagate = true;
|
||||||
|
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
|
||||||
|
search_bar.update(cx, |bar, cx| {
|
||||||
|
if let Some(_) = &bar.active_searchable_item {
|
||||||
|
should_propagate = false;
|
||||||
|
bar.replace_is_active = !bar.replace_is_active;
|
||||||
|
cx.notify();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if should_propagate {
|
||||||
|
cx.propagate_action();
|
||||||
|
}
|
||||||
|
}
|
||||||
fn replace_next(&mut self, _: &ReplaceNext, cx: &mut ViewContext<Self>) {
|
fn replace_next(&mut self, _: &ReplaceNext, cx: &mut ViewContext<Self>) {
|
||||||
if !self.dismissed && self.active_search.is_some() {
|
if !self.dismissed && self.active_search.is_some() {
|
||||||
if let Some(searchable_item) = self.active_searchable_item.as_ref() {
|
if let Some(searchable_item) = self.active_searchable_item.as_ref() {
|
||||||
|
@ -934,12 +950,16 @@ impl BufferSearchBar {
|
||||||
fn replace_next_on_pane(pane: &mut Pane, action: &ReplaceNext, cx: &mut ViewContext<Pane>) {
|
fn replace_next_on_pane(pane: &mut Pane, action: &ReplaceNext, cx: &mut ViewContext<Pane>) {
|
||||||
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
|
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
|
||||||
search_bar.update(cx, |bar, cx| bar.replace_next(action, cx));
|
search_bar.update(cx, |bar, cx| bar.replace_next(action, cx));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
cx.propagate_action();
|
||||||
}
|
}
|
||||||
fn replace_all_on_pane(pane: &mut Pane, action: &ReplaceAll, cx: &mut ViewContext<Pane>) {
|
fn replace_all_on_pane(pane: &mut Pane, action: &ReplaceAll, cx: &mut ViewContext<Pane>) {
|
||||||
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
|
if let Some(search_bar) = pane.toolbar().read(cx).item_of_type::<BufferSearchBar>() {
|
||||||
search_bar.update(cx, |bar, cx| bar.replace_all(action, cx));
|
search_bar.update(cx, |bar, cx| bar.replace_all(action, cx));
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
cx.propagate_action();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -992,7 +1012,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.all_background_highlights(cx),
|
editor.all_text_background_highlights(cx),
|
||||||
&[
|
&[
|
||||||
(
|
(
|
||||||
DisplayPoint::new(2, 17)..DisplayPoint::new(2, 19),
|
DisplayPoint::new(2, 17)..DisplayPoint::new(2, 19),
|
||||||
|
@ -1013,7 +1033,7 @@ mod tests {
|
||||||
editor.next_notification(cx).await;
|
editor.next_notification(cx).await;
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.all_background_highlights(cx),
|
editor.all_text_background_highlights(cx),
|
||||||
&[(
|
&[(
|
||||||
DisplayPoint::new(2, 43)..DisplayPoint::new(2, 45),
|
DisplayPoint::new(2, 43)..DisplayPoint::new(2, 45),
|
||||||
Color::red(),
|
Color::red(),
|
||||||
|
@ -1029,7 +1049,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.all_background_highlights(cx),
|
editor.all_text_background_highlights(cx),
|
||||||
&[
|
&[
|
||||||
(
|
(
|
||||||
DisplayPoint::new(0, 24)..DisplayPoint::new(0, 26),
|
DisplayPoint::new(0, 24)..DisplayPoint::new(0, 26),
|
||||||
|
@ -1070,7 +1090,7 @@ mod tests {
|
||||||
editor.next_notification(cx).await;
|
editor.next_notification(cx).await;
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.all_background_highlights(cx),
|
editor.all_text_background_highlights(cx),
|
||||||
&[
|
&[
|
||||||
(
|
(
|
||||||
DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43),
|
DisplayPoint::new(0, 41)..DisplayPoint::new(0, 43),
|
||||||
|
@ -1281,7 +1301,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.all_background_highlights(cx),
|
editor.all_text_background_highlights(cx),
|
||||||
&[(
|
&[(
|
||||||
DisplayPoint::new(2, 43)..DisplayPoint::new(2, 45),
|
DisplayPoint::new(2, 43)..DisplayPoint::new(2, 45),
|
||||||
Color::red(),
|
Color::red(),
|
||||||
|
@ -1308,7 +1328,7 @@ mod tests {
|
||||||
editor.next_notification(cx).await;
|
editor.next_notification(cx).await;
|
||||||
editor.update(cx, |editor, cx| {
|
editor.update(cx, |editor, cx| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
editor.all_background_highlights(cx),
|
editor.all_text_background_highlights(cx),
|
||||||
&[(
|
&[(
|
||||||
DisplayPoint::new(0, 35)..DisplayPoint::new(0, 40),
|
DisplayPoint::new(0, 35)..DisplayPoint::new(0, 40),
|
||||||
Color::red(),
|
Color::red(),
|
||||||
|
|
|
@ -701,8 +701,9 @@ impl ProjectSearchView {
|
||||||
}));
|
}));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
semantic_state.maintain_rate_limit = None;
|
||||||
}
|
}
|
||||||
semantic_state.maintain_rate_limit = None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1724,7 +1725,7 @@ pub mod tests {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
search_view
|
search_view
|
||||||
.results_editor
|
.results_editor
|
||||||
.update(cx, |editor, cx| editor.all_background_highlights(cx)),
|
.update(cx, |editor, cx| editor.all_text_background_highlights(cx)),
|
||||||
&[
|
&[
|
||||||
(
|
(
|
||||||
DisplayPoint::new(2, 32)..DisplayPoint::new(2, 35),
|
DisplayPoint::new(2, 32)..DisplayPoint::new(2, 35),
|
||||||
|
|
|
@ -110,7 +110,7 @@ fn toggle_replace_button<V: View>(
|
||||||
button_style: ToggleIconButtonStyle,
|
button_style: ToggleIconButtonStyle,
|
||||||
) -> AnyElement<V> {
|
) -> AnyElement<V> {
|
||||||
Button::dynamic_action(Box::new(ToggleReplace))
|
Button::dynamic_action(Box::new(ToggleReplace))
|
||||||
.with_tooltip("Toggle replace", tooltip_style)
|
.with_tooltip("Toggle Replace", tooltip_style)
|
||||||
.with_contents(theme::components::svg::Svg::new("icons/replace.svg"))
|
.with_contents(theme::components::svg::Svg::new("icons/replace.svg"))
|
||||||
.toggleable(active)
|
.toggleable(active)
|
||||||
.with_style(button_style)
|
.with_style(button_style)
|
||||||
|
|
|
@ -333,6 +333,7 @@ mod test {
|
||||||
cmd: false,
|
cmd: false,
|
||||||
function: false,
|
function: false,
|
||||||
key: "🖖🏻".to_string(), //2 char string
|
key: "🖖🏻".to_string(), //2 char string
|
||||||
|
ime_key: None,
|
||||||
};
|
};
|
||||||
assert_eq!(to_esc_str(&ks, &TermMode::NONE, false), None);
|
assert_eq!(to_esc_str(&ks, &TermMode::NONE, false), None);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,11 +34,11 @@ fn focused(EditorFocused(editor): &EditorFocused, cx: &mut AppContext) {
|
||||||
fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
fn blurred(EditorBlurred(editor): &EditorBlurred, cx: &mut AppContext) {
|
||||||
editor.window().update(cx, |cx| {
|
editor.window().update(cx, |cx| {
|
||||||
Vim::update(cx, |vim, cx| {
|
Vim::update(cx, |vim, cx| {
|
||||||
vim.clear_operator(cx);
|
|
||||||
vim.workspace_state.recording = false;
|
vim.workspace_state.recording = false;
|
||||||
vim.workspace_state.recorded_actions.clear();
|
vim.workspace_state.recorded_actions.clear();
|
||||||
if let Some(previous_editor) = vim.active_editor.clone() {
|
if let Some(previous_editor) = vim.active_editor.clone() {
|
||||||
if previous_editor == editor.clone() {
|
if previous_editor == editor.clone() {
|
||||||
|
vim.clear_operator(cx);
|
||||||
vim.active_editor = None;
|
vim.active_editor = None;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,3 +60,31 @@ fn released(EditorReleased(editor): &EditorReleased, cx: &mut AppContext) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod test {
|
||||||
|
use crate::{test::VimTestContext, Vim};
|
||||||
|
use editor::Editor;
|
||||||
|
use gpui::View;
|
||||||
|
use language::Buffer;
|
||||||
|
|
||||||
|
// regression test for blur called with a different active editor
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_blur_focus(cx: &mut gpui::TestAppContext) {
|
||||||
|
let mut cx = VimTestContext::new(cx, true).await;
|
||||||
|
|
||||||
|
let buffer = cx.add_model(|_| Buffer::new(0, 0, "a = 1\nb = 2\n"));
|
||||||
|
let window2 = cx.add_window(|cx| Editor::for_buffer(buffer, None, cx));
|
||||||
|
let editor2 = cx.read(|cx| window2.root(cx)).unwrap();
|
||||||
|
|
||||||
|
cx.update(|cx| {
|
||||||
|
let vim = Vim::read(cx);
|
||||||
|
assert_eq!(vim.active_editor.unwrap().id(), editor2.id())
|
||||||
|
});
|
||||||
|
|
||||||
|
// no panic when blurring an editor in a different window.
|
||||||
|
cx.update_editor(|editor1, cx| {
|
||||||
|
editor1.focus_out(cx.handle().into_any(), cx);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -533,11 +533,15 @@ fn down(
|
||||||
|
|
||||||
let new_row = cmp::min(
|
let new_row = cmp::min(
|
||||||
start.row() + times as u32,
|
start.row() + times as u32,
|
||||||
map.buffer_snapshot.max_point().row,
|
map.fold_snapshot.max_point().row(),
|
||||||
);
|
);
|
||||||
let new_col = cmp::min(goal_column, map.fold_snapshot.line_len(new_row));
|
let new_col = cmp::min(goal_column, map.fold_snapshot.line_len(new_row));
|
||||||
let point = map.fold_point_to_display_point(FoldPoint::new(new_row, new_col));
|
let point = map.fold_point_to_display_point(
|
||||||
|
map.fold_snapshot
|
||||||
|
.clip_point(FoldPoint::new(new_row, new_col), Bias::Left),
|
||||||
|
);
|
||||||
|
|
||||||
|
// clip twice to "clip at end of line"
|
||||||
(map.clip_point(point, Bias::Left), goal)
|
(map.clip_point(point, Bias::Left), goal)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -573,7 +577,10 @@ pub(crate) fn up(
|
||||||
|
|
||||||
let new_row = start.row().saturating_sub(times as u32);
|
let new_row = start.row().saturating_sub(times as u32);
|
||||||
let new_col = cmp::min(goal_column, map.fold_snapshot.line_len(new_row));
|
let new_col = cmp::min(goal_column, map.fold_snapshot.line_len(new_row));
|
||||||
let point = map.fold_point_to_display_point(FoldPoint::new(new_row, new_col));
|
let point = map.fold_point_to_display_point(
|
||||||
|
map.fold_snapshot
|
||||||
|
.clip_point(FoldPoint::new(new_row, new_col), Bias::Left),
|
||||||
|
);
|
||||||
|
|
||||||
(map.clip_point(point, Bias::Left), goal)
|
(map.clip_point(point, Bias::Left), goal)
|
||||||
}
|
}
|
||||||
|
|
|
@ -227,7 +227,7 @@ mod test {
|
||||||
deterministic.run_until_parked();
|
deterministic.run_until_parked();
|
||||||
|
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
let highlights = editor.all_background_highlights(cx);
|
let highlights = editor.all_text_background_highlights(cx);
|
||||||
assert_eq!(3, highlights.len());
|
assert_eq!(3, highlights.len());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2),
|
DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2),
|
||||||
|
|
|
@ -186,7 +186,6 @@ impl EditorState {
|
||||||
if self.active_operator().is_none() && self.pre_count.is_some()
|
if self.active_operator().is_none() && self.pre_count.is_some()
|
||||||
|| self.active_operator().is_some() && self.post_count.is_some()
|
|| self.active_operator().is_some() && self.post_count.is_some()
|
||||||
{
|
{
|
||||||
dbg!("VimCount");
|
|
||||||
context.add_identifier("VimCount");
|
context.add_identifier("VimCount");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -190,7 +190,7 @@ async fn test_selection_on_search(cx: &mut gpui::TestAppContext) {
|
||||||
search_bar.next_notification(&cx).await;
|
search_bar.next_notification(&cx).await;
|
||||||
|
|
||||||
cx.update_editor(|editor, cx| {
|
cx.update_editor(|editor, cx| {
|
||||||
let highlights = editor.all_background_highlights(cx);
|
let highlights = editor.all_text_background_highlights(cx);
|
||||||
assert_eq!(3, highlights.len());
|
assert_eq!(3, highlights.len());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2),
|
DisplayPoint::new(2, 0)..DisplayPoint::new(2, 2),
|
||||||
|
@ -575,6 +575,26 @@ async fn test_folds(cx: &mut gpui::TestAppContext) {
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[gpui::test]
|
||||||
|
async fn test_folds_panic(cx: &mut gpui::TestAppContext) {
|
||||||
|
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||||
|
cx.set_neovim_option("foldmethod=manual").await;
|
||||||
|
|
||||||
|
cx.set_shared_state(indoc! { "
|
||||||
|
fn boop() {
|
||||||
|
ˇbarp()
|
||||||
|
bazp()
|
||||||
|
}
|
||||||
|
"})
|
||||||
|
.await;
|
||||||
|
cx.simulate_shared_keystrokes(["shift-v", "j", "z", "f"])
|
||||||
|
.await;
|
||||||
|
cx.simulate_shared_keystrokes(["escape"]).await;
|
||||||
|
cx.simulate_shared_keystrokes(["g", "g"]).await;
|
||||||
|
cx.simulate_shared_keystrokes(["5", "d", "j"]).await;
|
||||||
|
cx.assert_shared_state(indoc! { "ˇ"}).await;
|
||||||
|
}
|
||||||
|
|
||||||
#[gpui::test]
|
#[gpui::test]
|
||||||
async fn test_clear_counts(cx: &mut gpui::TestAppContext) {
|
async fn test_clear_counts(cx: &mut gpui::TestAppContext) {
|
||||||
let mut cx = NeovimBackedTestContext::new(cx).await;
|
let mut cx = NeovimBackedTestContext::new(cx).await;
|
||||||
|
|
13
crates/vim/test_data/test_folds_panic.json
Normal file
13
crates/vim/test_data/test_folds_panic.json
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
{"SetOption":{"value":"foldmethod=manual"}}
|
||||||
|
{"Put":{"state":"fn boop() {\n ˇbarp()\n bazp()\n}\n"}}
|
||||||
|
{"Key":"shift-v"}
|
||||||
|
{"Key":"j"}
|
||||||
|
{"Key":"z"}
|
||||||
|
{"Key":"f"}
|
||||||
|
{"Key":"escape"}
|
||||||
|
{"Key":"g"}
|
||||||
|
{"Key":"g"}
|
||||||
|
{"Key":"5"}
|
||||||
|
{"Key":"d"}
|
||||||
|
{"Key":"j"}
|
||||||
|
{"Get":{"state":"ˇ","mode":"Normal"}}
|
|
@ -3,7 +3,7 @@ authors = ["Nathan Sobo <nathansobo@gmail.com>"]
|
||||||
description = "The fast, collaborative code editor."
|
description = "The fast, collaborative code editor."
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
name = "zed"
|
name = "zed"
|
||||||
version = "0.104.0"
|
version = "0.104.4"
|
||||||
publish = false
|
publish = false
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
dev
|
stable
|
Loading…
Add table
Add a link
Reference in a new issue