mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-02 23:12:21 +03:00
Unify text and inlay highlights
This commit is contained in:
parent
420f8b7b15
commit
12ffbe54fb
@ -5,8 +5,8 @@ mod tab_map;
|
|||||||
mod wrap_map;
|
mod wrap_map;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
link_go_to_definition::InlayRange, Anchor, AnchorRangeExt, InlayId, MultiBuffer,
|
link_go_to_definition::{DocumentRange, InlayRange},
|
||||||
MultiBufferSnapshot, ToOffset, ToPoint,
|
Anchor, AnchorRangeExt, InlayId, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint,
|
||||||
};
|
};
|
||||||
pub use block_map::{BlockMap, BlockPoint};
|
pub use block_map::{BlockMap, BlockPoint};
|
||||||
use collections::{HashMap, HashSet};
|
use collections::{HashMap, HashSet};
|
||||||
@ -42,8 +42,7 @@ 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<Range<Anchor>>)>>;
|
type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<DocumentRange>)>>;
|
||||||
type InlayHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<InlayRange>)>>;
|
|
||||||
|
|
||||||
pub struct DisplayMap {
|
pub struct DisplayMap {
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
buffer: ModelHandle<MultiBuffer>,
|
||||||
@ -54,7 +53,6 @@ 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +88,6 @@ 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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +112,6 @@ 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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -218,8 +214,10 @@ impl DisplayMap {
|
|||||||
ranges: Vec<Range<Anchor>>,
|
ranges: Vec<Range<Anchor>>,
|
||||||
style: HighlightStyle,
|
style: HighlightStyle,
|
||||||
) {
|
) {
|
||||||
self.text_highlights
|
self.text_highlights.insert(
|
||||||
.insert(Some(type_id), Arc::new((style, ranges)));
|
Some(type_id),
|
||||||
|
Arc::new((style, ranges.into_iter().map(DocumentRange::Text).collect())),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn highlight_inlays(
|
pub fn highlight_inlays(
|
||||||
@ -228,11 +226,16 @@ impl DisplayMap {
|
|||||||
ranges: Vec<InlayRange>,
|
ranges: Vec<InlayRange>,
|
||||||
style: HighlightStyle,
|
style: HighlightStyle,
|
||||||
) {
|
) {
|
||||||
self.inlay_highlights
|
self.text_highlights.insert(
|
||||||
.insert(Some(type_id), Arc::new((style, ranges)));
|
Some(type_id),
|
||||||
|
Arc::new((
|
||||||
|
style,
|
||||||
|
ranges.into_iter().map(DocumentRange::Inlay).collect(),
|
||||||
|
)),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_highlights(&self, type_id: TypeId) -> Option<(HighlightStyle, &[Range<Anchor>])> {
|
pub fn text_highlights(&self, type_id: TypeId) -> Option<(HighlightStyle, &[DocumentRange])> {
|
||||||
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))
|
||||||
}
|
}
|
||||||
@ -240,17 +243,10 @@ impl DisplayMap {
|
|||||||
pub fn clear_text_highlights(
|
pub fn clear_text_highlights(
|
||||||
&mut self,
|
&mut self,
|
||||||
type_id: TypeId,
|
type_id: TypeId,
|
||||||
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
|
) -> Option<Arc<(HighlightStyle, Vec<DocumentRange>)>> {
|
||||||
self.text_highlights.remove(&Some(type_id))
|
self.text_highlights.remove(&Some(type_id))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_inlay_highlights(
|
|
||||||
&mut self,
|
|
||||||
type_id: TypeId,
|
|
||||||
) -> Option<Arc<(HighlightStyle, Vec<InlayRange>)>> {
|
|
||||||
self.inlay_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 {
|
||||||
self.wrap_map
|
self.wrap_map
|
||||||
.update(cx, |map, cx| map.set_font(font_id, font_size, cx))
|
.update(cx, |map, cx| map.set_font(font_id, font_size, cx))
|
||||||
@ -320,7 +316,6 @@ 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -446,7 +441,6 @@ impl DisplaySnapshot {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.map(|h| h.text)
|
.map(|h| h.text)
|
||||||
}
|
}
|
||||||
@ -455,7 +449,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, None)
|
.chunks(row..row + 1, false, None, None, None)
|
||||||
.map(|h| h.text)
|
.map(|h| h.text)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -474,7 +468,6 @@ impl DisplaySnapshot {
|
|||||||
display_rows,
|
display_rows,
|
||||||
language_aware,
|
language_aware,
|
||||||
Some(&self.text_highlights),
|
Some(&self.text_highlights),
|
||||||
Some(&self.inlay_highlights),
|
|
||||||
inlay_highlight_style,
|
inlay_highlight_style,
|
||||||
suggestion_highlight_style,
|
suggestion_highlight_style,
|
||||||
)
|
)
|
||||||
@ -797,7 +790,7 @@ impl DisplaySnapshot {
|
|||||||
#[cfg(any(test, feature = "test-support"))]
|
#[cfg(any(test, feature = "test-support"))]
|
||||||
pub fn highlight_ranges<Tag: ?Sized + 'static>(
|
pub fn highlight_ranges<Tag: ?Sized + 'static>(
|
||||||
&self,
|
&self,
|
||||||
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
|
) -> Option<Arc<(HighlightStyle, Vec<DocumentRange>)>> {
|
||||||
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()
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use super::{
|
use super::{
|
||||||
wrap_map::{self, WrapEdit, WrapPoint, WrapSnapshot},
|
wrap_map::{self, WrapEdit, WrapPoint, WrapSnapshot},
|
||||||
InlayHighlights, TextHighlights,
|
TextHighlights,
|
||||||
};
|
};
|
||||||
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};
|
||||||
@ -579,7 +579,6 @@ impl BlockSnapshot {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.map(|chunk| chunk.text)
|
.map(|chunk| chunk.text)
|
||||||
.collect()
|
.collect()
|
||||||
@ -590,7 +589,6 @@ impl BlockSnapshot {
|
|||||||
rows: Range<u32>,
|
rows: Range<u32>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
text_highlights: Option<&'a TextHighlights>,
|
||||||
inlay_highlights: Option<&'a InlayHighlights>,
|
|
||||||
inlay_highlight_style: Option<HighlightStyle>,
|
inlay_highlight_style: Option<HighlightStyle>,
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
suggestion_highlight_style: Option<HighlightStyle>,
|
||||||
) -> BlockChunks<'a> {
|
) -> BlockChunks<'a> {
|
||||||
@ -625,7 +623,6 @@ impl BlockSnapshot {
|
|||||||
input_start..input_end,
|
input_start..input_end,
|
||||||
language_aware,
|
language_aware,
|
||||||
text_highlights,
|
text_highlights,
|
||||||
inlay_highlights,
|
|
||||||
inlay_highlight_style,
|
inlay_highlight_style,
|
||||||
suggestion_highlight_style,
|
suggestion_highlight_style,
|
||||||
),
|
),
|
||||||
@ -1507,7 +1504,6 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
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},
|
||||||
InlayHighlights, TextHighlights,
|
TextHighlights,
|
||||||
};
|
};
|
||||||
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, None)
|
self.chunks(FoldOffset(0)..self.len(), false, None, None, None)
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
@ -652,7 +652,6 @@ impl FoldSnapshot {
|
|||||||
range: Range<FoldOffset>,
|
range: Range<FoldOffset>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
text_highlights: Option<&'a TextHighlights>,
|
||||||
inlay_highlights: Option<&'a InlayHighlights>,
|
|
||||||
inlay_highlight_style: Option<HighlightStyle>,
|
inlay_highlight_style: Option<HighlightStyle>,
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
suggestion_highlight_style: Option<HighlightStyle>,
|
||||||
) -> FoldChunks<'a> {
|
) -> FoldChunks<'a> {
|
||||||
@ -676,7 +675,6 @@ impl FoldSnapshot {
|
|||||||
inlay_start..inlay_end,
|
inlay_start..inlay_end,
|
||||||
language_aware,
|
language_aware,
|
||||||
text_highlights,
|
text_highlights,
|
||||||
inlay_highlights,
|
|
||||||
inlay_highlight_style,
|
inlay_highlight_style,
|
||||||
suggestion_highlight_style,
|
suggestion_highlight_style,
|
||||||
),
|
),
|
||||||
@ -689,15 +687,8 @@ 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(
|
self.chunks(start.to_offset(self)..self.len(), false, None, None, None)
|
||||||
start.to_offset(self)..self.len(),
|
.flat_map(|chunk| chunk.text.chars())
|
||||||
false,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.flat_map(|chunk| chunk.text.chars())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@ -1505,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, None)
|
.chunks(start..end, false, None, None, None)
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
text,
|
text,
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
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,
|
||||||
};
|
};
|
||||||
use collections::{BTreeMap, BTreeSet, HashSet};
|
use collections::{BTreeMap, BTreeSet};
|
||||||
use gpui::fonts::HighlightStyle;
|
use gpui::fonts::HighlightStyle;
|
||||||
use language::{Chunk, Edit, Point, TextSummary};
|
use language::{Chunk, Edit, Point, TextSummary};
|
||||||
use std::{
|
use std::{
|
||||||
@ -15,7 +16,7 @@ use std::{
|
|||||||
use sum_tree::{Bias, Cursor, SumTree};
|
use sum_tree::{Bias, Cursor, SumTree};
|
||||||
use text::{Patch, Rope};
|
use text::{Patch, Rope};
|
||||||
|
|
||||||
use super::{InlayHighlights, TextHighlights};
|
use super::TextHighlights;
|
||||||
|
|
||||||
pub struct InlayMap {
|
pub struct InlayMap {
|
||||||
snapshot: InlaySnapshot,
|
snapshot: InlaySnapshot,
|
||||||
@ -244,7 +245,6 @@ impl<'a> Iterator for InlayChunks<'a> {
|
|||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO kb highlights are not displayed still
|
|
||||||
let mut next_highlight_endpoint = InlayOffset(usize::MAX);
|
let mut next_highlight_endpoint = InlayOffset(usize::MAX);
|
||||||
while let Some(endpoint) = self.highlight_endpoints.peek().copied() {
|
while let Some(endpoint) = self.highlight_endpoints.peek().copied() {
|
||||||
if endpoint.offset <= self.output_offset {
|
if endpoint.offset <= self.output_offset {
|
||||||
@ -993,7 +993,6 @@ impl InlaySnapshot {
|
|||||||
range: Range<InlayOffset>,
|
range: Range<InlayOffset>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
text_highlights: Option<&'a TextHighlights>,
|
||||||
inlay_highlights: Option<&'a InlayHighlights>,
|
|
||||||
inlay_highlight_style: Option<HighlightStyle>,
|
inlay_highlight_style: Option<HighlightStyle>,
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
suggestion_highlight_style: Option<HighlightStyle>,
|
||||||
) -> InlayChunks<'a> {
|
) -> InlayChunks<'a> {
|
||||||
@ -1002,15 +1001,14 @@ impl InlaySnapshot {
|
|||||||
|
|
||||||
let empty_text_highlights = TextHighlights::default();
|
let empty_text_highlights = TextHighlights::default();
|
||||||
let text_highlights = text_highlights.unwrap_or_else(|| &empty_text_highlights);
|
let text_highlights = text_highlights.unwrap_or_else(|| &empty_text_highlights);
|
||||||
let empty_inlay_highlights = InlayHighlights::default();
|
|
||||||
let inlay_highlights = inlay_highlights.unwrap_or_else(|| &empty_inlay_highlights);
|
|
||||||
|
|
||||||
let mut highlight_endpoints = Vec::new();
|
let mut highlight_endpoints = Vec::new();
|
||||||
if !text_highlights.is_empty() || !inlay_highlights.is_empty() {
|
if !text_highlights.is_empty() {
|
||||||
while cursor.start().0 < range.end {
|
while cursor.start().0 < range.end {
|
||||||
let transform_start = self
|
let transform_start = self
|
||||||
.buffer
|
.buffer
|
||||||
.anchor_after(self.to_buffer_offset(cmp::max(range.start, cursor.start().0)));
|
.anchor_after(self.to_buffer_offset(cmp::max(range.start, cursor.start().0)));
|
||||||
|
let transform_start = self.to_inlay_offset(transform_start.to_offset(&self.buffer));
|
||||||
|
|
||||||
let transform_end = {
|
let transform_end = {
|
||||||
let overshoot = InlayOffset(range.end.0 - cursor.start().0 .0);
|
let overshoot = InlayOffset(range.end.0 - cursor.start().0 .0);
|
||||||
@ -1019,15 +1017,17 @@ impl InlaySnapshot {
|
|||||||
cursor.start().0 + overshoot,
|
cursor.start().0 + overshoot,
|
||||||
)))
|
)))
|
||||||
};
|
};
|
||||||
|
let transform_end = self.to_inlay_offset(transform_end.to_offset(&self.buffer));
|
||||||
|
|
||||||
let mut covered_tags = HashSet::default();
|
|
||||||
for (tag, text_highlights) in text_highlights.iter() {
|
for (tag, text_highlights) in text_highlights.iter() {
|
||||||
covered_tags.insert(*tag);
|
|
||||||
let style = text_highlights.0;
|
let style = text_highlights.0;
|
||||||
let ranges = &text_highlights.1;
|
let ranges = &text_highlights.1;
|
||||||
|
|
||||||
let start_ix = match ranges.binary_search_by(|probe| {
|
let start_ix = match ranges.binary_search_by(|probe| {
|
||||||
let cmp = probe.end.cmp(&transform_start, &self.buffer);
|
let cmp = self
|
||||||
|
.document_to_inlay_range(probe)
|
||||||
|
.end
|
||||||
|
.cmp(&transform_start);
|
||||||
if cmp.is_gt() {
|
if cmp.is_gt() {
|
||||||
cmp::Ordering::Greater
|
cmp::Ordering::Greater
|
||||||
} else {
|
} else {
|
||||||
@ -1037,46 +1037,24 @@ impl InlaySnapshot {
|
|||||||
Ok(i) | Err(i) => i,
|
Ok(i) | Err(i) => i,
|
||||||
};
|
};
|
||||||
for range in &ranges[start_ix..] {
|
for range in &ranges[start_ix..] {
|
||||||
if range.start.cmp(&transform_end, &self.buffer).is_ge() {
|
let range = self.document_to_inlay_range(range);
|
||||||
|
if range.start.cmp(&transform_end).is_ge() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
highlight_endpoints.push(HighlightEndpoint {
|
highlight_endpoints.push(HighlightEndpoint {
|
||||||
offset: self.to_inlay_offset(range.start.to_offset(&self.buffer)),
|
offset: range.start,
|
||||||
is_start: true,
|
is_start: true,
|
||||||
tag: *tag,
|
tag: *tag,
|
||||||
style,
|
style,
|
||||||
});
|
});
|
||||||
highlight_endpoints.push(HighlightEndpoint {
|
highlight_endpoints.push(HighlightEndpoint {
|
||||||
offset: self.to_inlay_offset(range.end.to_offset(&self.buffer)),
|
offset: range.end,
|
||||||
is_start: false,
|
is_start: false,
|
||||||
tag: *tag,
|
tag: *tag,
|
||||||
style,
|
style,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(inlay_highlights) = inlay_highlights.get(tag) {
|
|
||||||
self.push_inlay_highlight_range(
|
|
||||||
inlay_highlights,
|
|
||||||
transform_start,
|
|
||||||
transform_end,
|
|
||||||
&mut highlight_endpoints,
|
|
||||||
tag,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (tag, inlay_highlights) in inlay_highlights
|
|
||||||
.iter()
|
|
||||||
.filter(|(tag, _)| !covered_tags.contains(tag))
|
|
||||||
{
|
|
||||||
self.push_inlay_highlight_range(
|
|
||||||
inlay_highlights,
|
|
||||||
transform_start,
|
|
||||||
transform_end,
|
|
||||||
&mut highlight_endpoints,
|
|
||||||
tag,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.next(&());
|
cursor.next(&());
|
||||||
@ -1104,60 +1082,23 @@ impl InlaySnapshot {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_inlay_highlight_range(
|
fn document_to_inlay_range(&self, range: &DocumentRange) -> Range<InlayOffset> {
|
||||||
&self,
|
match range {
|
||||||
inlay_highlights: &std::sync::Arc<(
|
DocumentRange::Text(text_range) => {
|
||||||
HighlightStyle,
|
self.to_inlay_offset(text_range.start.to_offset(&self.buffer))
|
||||||
Vec<crate::link_go_to_definition::InlayRange>,
|
..self.to_inlay_offset(text_range.end.to_offset(&self.buffer))
|
||||||
)>,
|
}
|
||||||
transform_start: Anchor,
|
DocumentRange::Inlay(inlay_range) => {
|
||||||
transform_end: Anchor,
|
inlay_range.highlight_start..inlay_range.highlight_end
|
||||||
highlight_endpoints: &mut Vec<HighlightEndpoint>,
|
|
||||||
tag: &Option<TypeId>,
|
|
||||||
) {
|
|
||||||
let style = inlay_highlights.0;
|
|
||||||
let ranges = &inlay_highlights.1;
|
|
||||||
let start_ix = match ranges
|
|
||||||
.binary_search_by(|probe| probe.inlay_position.cmp(&transform_start, &self.buffer))
|
|
||||||
{
|
|
||||||
Ok(i) | Err(i) => i,
|
|
||||||
};
|
|
||||||
for range in &ranges[start_ix..] {
|
|
||||||
if range
|
|
||||||
.inlay_position
|
|
||||||
.cmp(&transform_end, &self.buffer)
|
|
||||||
.is_ge()
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
highlight_endpoints.push(HighlightEndpoint {
|
|
||||||
offset: range.highlight_start,
|
|
||||||
is_start: true,
|
|
||||||
tag: *tag,
|
|
||||||
style,
|
|
||||||
});
|
|
||||||
highlight_endpoints.push(HighlightEndpoint {
|
|
||||||
offset: range.highlight_end,
|
|
||||||
is_start: false,
|
|
||||||
tag: *tag,
|
|
||||||
style,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn text(&self) -> String {
|
pub fn text(&self) -> String {
|
||||||
self.chunks(
|
self.chunks(Default::default()..self.len(), false, None, None, None)
|
||||||
Default::default()..self.len(),
|
.map(|chunk| chunk.text)
|
||||||
false,
|
.collect()
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.map(|chunk| chunk.text)
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_invariants(&self) {
|
fn check_invariants(&self) {
|
||||||
@ -1651,6 +1592,8 @@ mod tests {
|
|||||||
.map(|range| {
|
.map(|range| {
|
||||||
buffer_snapshot.anchor_before(range.start)..buffer_snapshot.anchor_after(range.end)
|
buffer_snapshot.anchor_before(range.start)..buffer_snapshot.anchor_after(range.end)
|
||||||
})
|
})
|
||||||
|
// TODO add inlay highlight tests
|
||||||
|
.map(DocumentRange::Text)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
highlights.insert(
|
highlights.insert(
|
||||||
@ -1731,8 +1674,6 @@ mod tests {
|
|||||||
InlayOffset(start)..InlayOffset(end),
|
InlayOffset(start)..InlayOffset(end),
|
||||||
false,
|
false,
|
||||||
Some(&highlights),
|
Some(&highlights),
|
||||||
// TODO kb add tests
|
|
||||||
None,
|
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use super::{
|
use super::{
|
||||||
fold_map::{self, FoldChunks, FoldEdit, FoldPoint, FoldSnapshot},
|
fold_map::{self, FoldChunks, FoldEdit, FoldPoint, FoldSnapshot},
|
||||||
InlayHighlights, TextHighlights,
|
TextHighlights,
|
||||||
};
|
};
|
||||||
use crate::MultiBufferSnapshot;
|
use crate::MultiBufferSnapshot;
|
||||||
use gpui::fonts::HighlightStyle;
|
use gpui::fonts::HighlightStyle;
|
||||||
@ -71,7 +71,6 @@ impl TabMap {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
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);
|
||||||
@ -184,7 +183,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, None)
|
.chunks(range.start..line_end, false, None, None, None)
|
||||||
.flat_map(|chunk| chunk.text.chars())
|
.flat_map(|chunk| chunk.text.chars())
|
||||||
{
|
{
|
||||||
if c == '\n' {
|
if c == '\n' {
|
||||||
@ -204,7 +203,6 @@ impl TabSnapshot {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.flat_map(|chunk| chunk.text.chars())
|
.flat_map(|chunk| chunk.text.chars())
|
||||||
{
|
{
|
||||||
@ -225,9 +223,8 @@ impl TabSnapshot {
|
|||||||
&'a self,
|
&'a self,
|
||||||
range: Range<TabPoint>,
|
range: Range<TabPoint>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
// TODO kb extract into one struct
|
// TODO kb extract into one struct?
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
text_highlights: Option<&'a TextHighlights>,
|
||||||
inlay_highlights: Option<&'a InlayHighlights>,
|
|
||||||
inlay_highlight_style: Option<HighlightStyle>,
|
inlay_highlight_style: Option<HighlightStyle>,
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
suggestion_highlight_style: Option<HighlightStyle>,
|
||||||
) -> TabChunks<'a> {
|
) -> TabChunks<'a> {
|
||||||
@ -250,7 +247,6 @@ impl TabSnapshot {
|
|||||||
input_start..input_end,
|
input_start..input_end,
|
||||||
language_aware,
|
language_aware,
|
||||||
text_highlights,
|
text_highlights,
|
||||||
inlay_highlights,
|
|
||||||
inlay_highlight_style,
|
inlay_highlight_style,
|
||||||
suggestion_highlight_style,
|
suggestion_highlight_style,
|
||||||
),
|
),
|
||||||
@ -275,16 +271,9 @@ impl TabSnapshot {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn text(&self) -> String {
|
pub fn text(&self) -> String {
|
||||||
self.chunks(
|
self.chunks(TabPoint::zero()..self.max_point(), false, None, None, None)
|
||||||
TabPoint::zero()..self.max_point(),
|
.map(|chunk| chunk.text)
|
||||||
false,
|
.collect()
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
)
|
|
||||||
.map(|chunk| chunk.text)
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn max_point(&self) -> TabPoint {
|
pub fn max_point(&self) -> TabPoint {
|
||||||
@ -612,7 +601,6 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
@ -687,8 +675,7 @@ 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, None)
|
for chunk in snapshot.chunks(start..snapshot.max_point(), false, None, None, None) {
|
||||||
{
|
|
||||||
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));
|
||||||
@ -757,7 +744,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, None)
|
.chunks(start..end, false, None, None, None)
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect::<String>(),
|
.collect::<String>(),
|
||||||
expected_text,
|
expected_text,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use super::{
|
use super::{
|
||||||
fold_map::FoldBufferRows,
|
fold_map::FoldBufferRows,
|
||||||
tab_map::{self, TabEdit, TabPoint, TabSnapshot},
|
tab_map::{self, TabEdit, TabPoint, TabSnapshot},
|
||||||
InlayHighlights, TextHighlights,
|
TextHighlights,
|
||||||
};
|
};
|
||||||
use crate::MultiBufferSnapshot;
|
use crate::MultiBufferSnapshot;
|
||||||
use gpui::{
|
use gpui::{
|
||||||
@ -447,7 +447,6 @@ impl WrapSnapshot {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
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 {
|
||||||
@ -577,7 +576,6 @@ impl WrapSnapshot {
|
|||||||
rows: Range<u32>,
|
rows: Range<u32>,
|
||||||
language_aware: bool,
|
language_aware: bool,
|
||||||
text_highlights: Option<&'a TextHighlights>,
|
text_highlights: Option<&'a TextHighlights>,
|
||||||
inlay_highlights: Option<&'a InlayHighlights>,
|
|
||||||
inlay_highlight_style: Option<HighlightStyle>,
|
inlay_highlight_style: Option<HighlightStyle>,
|
||||||
suggestion_highlight_style: Option<HighlightStyle>,
|
suggestion_highlight_style: Option<HighlightStyle>,
|
||||||
) -> WrapChunks<'a> {
|
) -> WrapChunks<'a> {
|
||||||
@ -597,7 +595,6 @@ impl WrapSnapshot {
|
|||||||
input_start..input_end,
|
input_start..input_end,
|
||||||
language_aware,
|
language_aware,
|
||||||
text_highlights,
|
text_highlights,
|
||||||
inlay_highlights,
|
|
||||||
inlay_highlight_style,
|
inlay_highlight_style,
|
||||||
suggestion_highlight_style,
|
suggestion_highlight_style,
|
||||||
),
|
),
|
||||||
@ -1329,7 +1326,6 @@ mod tests {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.map(|h| h.text)
|
.map(|h| h.text)
|
||||||
}
|
}
|
||||||
@ -1354,7 +1350,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let actual_text = self
|
let actual_text = self
|
||||||
.chunks(start_row..end_row, true, None, None, None, None)
|
.chunks(start_row..end_row, true, None, None, None)
|
||||||
.map(|c| c.text)
|
.map(|c| c.text)
|
||||||
.collect::<String>();
|
.collect::<String>();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -65,7 +65,7 @@ use language::{
|
|||||||
OffsetUtf16, Point, Selection, SelectionGoal, TransactionId,
|
OffsetUtf16, Point, Selection, SelectionGoal, TransactionId,
|
||||||
};
|
};
|
||||||
use link_go_to_definition::{
|
use link_go_to_definition::{
|
||||||
hide_link_definition, show_link_definition, InlayRange, LinkGoToDefinitionState,
|
hide_link_definition, show_link_definition, DocumentRange, InlayRange, LinkGoToDefinitionState,
|
||||||
};
|
};
|
||||||
use log::error;
|
use log::error;
|
||||||
use multi_buffer::ToOffsetUtf16;
|
use multi_buffer::ToOffsetUtf16;
|
||||||
@ -7733,7 +7733,7 @@ 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 [Range<Anchor>])> {
|
) -> Option<(HighlightStyle, &'a [DocumentRange])> {
|
||||||
self.display_map.read(cx).text_highlights(TypeId::of::<T>())
|
self.display_map.read(cx).text_highlights(TypeId::of::<T>())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -7741,10 +7741,7 @@ impl Editor {
|
|||||||
let text_highlights = self
|
let text_highlights = self
|
||||||
.display_map
|
.display_map
|
||||||
.update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()));
|
.update(cx, |map, _| map.clear_text_highlights(TypeId::of::<T>()));
|
||||||
let inlay_highlights = self
|
if text_highlights.is_some() {
|
||||||
.display_map
|
|
||||||
.update(cx, |map, _| map.clear_inlay_highlights(TypeId::of::<T>()));
|
|
||||||
if text_highlights.is_some() || inlay_highlights.is_some() {
|
|
||||||
cx.notify();
|
cx.notify();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7953,6 +7950,8 @@ impl Editor {
|
|||||||
Some(
|
Some(
|
||||||
ranges
|
ranges
|
||||||
.iter()
|
.iter()
|
||||||
|
// TODO kb mark inlays too
|
||||||
|
.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)
|
||||||
})
|
})
|
||||||
@ -8406,6 +8405,8 @@ 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)?;
|
||||||
|
// TODO kb mark inlays too
|
||||||
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,6 +43,13 @@ pub enum DocumentRange {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DocumentRange {
|
impl DocumentRange {
|
||||||
|
pub fn as_text_range(&self) -> Option<Range<Anchor>> {
|
||||||
|
match self {
|
||||||
|
Self::Text(range) => Some(range.clone()),
|
||||||
|
Self::Inlay(_) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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)) => {
|
(DocumentRange::Text(range), TriggerPoint::Text(point)) => {
|
||||||
|
@ -240,6 +240,7 @@ impl<'a> EditorTestContext<'a> {
|
|||||||
.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);
|
||||||
|
Loading…
Reference in New Issue
Block a user