Unify highlights in *Map
This commit is contained in:
parent
6c00cd8a35
commit
9f5314e938
10 changed files with 100 additions and 118 deletions
|
@ -702,7 +702,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,
|
||||||
|
|
|
@ -43,8 +43,8 @@ pub trait ToDisplayPoint {
|
||||||
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint;
|
fn to_display_point(&self, map: &DisplaySnapshot) -> DisplayPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO kb InlayHighlights = ... ?
|
|
||||||
type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;
|
type TextHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<Range<Anchor>>)>>;
|
||||||
|
type InlayHighlights = TreeMap<Option<TypeId>, Arc<(HighlightStyle, Vec<InlayRange>)>>;
|
||||||
|
|
||||||
pub struct DisplayMap {
|
pub struct DisplayMap {
|
||||||
buffer: ModelHandle<MultiBuffer>,
|
buffer: ModelHandle<MultiBuffer>,
|
||||||
|
@ -55,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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,26 +229,18 @@ impl DisplayMap {
|
||||||
ranges: Vec<InlayRange>,
|
ranges: Vec<InlayRange>,
|
||||||
style: HighlightStyle,
|
style: HighlightStyle,
|
||||||
) {
|
) {
|
||||||
// TODO kb
|
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, &[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(&Some(type_id)).is_none();
|
||||||
type_id: TypeId,
|
cleared
|
||||||
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
|
|
||||||
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 {
|
||||||
|
@ -317,9 +312,18 @@ 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,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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>,
|
||||||
|
}
|
||||||
|
|
||||||
impl DisplaySnapshot {
|
impl DisplaySnapshot {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn fold_count(&self) -> usize {
|
pub fn fold_count(&self) -> usize {
|
||||||
|
@ -454,9 +458,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)
|
||||||
}
|
}
|
||||||
|
@ -465,7 +467,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()
|
||||||
|
@ -477,15 +479,18 @@ impl DisplaySnapshot {
|
||||||
&self,
|
&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,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,7 +748,7 @@ 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<Range<Anchor>>)>> {
|
) -> Option<Arc<(HighlightStyle, Vec<Range<Anchor>>)>> {
|
||||||
let type_id = TypeId::of::<Tag>();
|
let type_id = TypeId::of::<Tag>();
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -15,7 +15,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::TextHighlights;
|
use super::Highlights;
|
||||||
|
|
||||||
pub struct InlayMap {
|
pub struct InlayMap {
|
||||||
snapshot: InlaySnapshot,
|
snapshot: InlaySnapshot,
|
||||||
|
@ -213,7 +213,7 @@ 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>,
|
||||||
|
@ -314,7 +314,7 @@ impl<'a> Iterator for InlayChunks<'a> {
|
||||||
self.output_offset.0 += chunk.len();
|
self.output_offset.0 += chunk.len();
|
||||||
let mut highlight_style = match inlay.id {
|
let mut highlight_style = match inlay.id {
|
||||||
InlayId::Suggestion(_) => self.suggestion_highlight_style,
|
InlayId::Suggestion(_) => self.suggestion_highlight_style,
|
||||||
InlayId::Hint(_) => self.hint_highlight_style,
|
InlayId::Hint(_) => self.inlay_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() {
|
||||||
|
@ -991,15 +991,13 @@ 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 {
|
while cursor.start().0 < range.end {
|
||||||
let transform_start = self.buffer.anchor_after(
|
let transform_start = self.buffer.anchor_after(
|
||||||
|
@ -1065,8 +1063,8 @@ 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(),
|
||||||
snapshot: self,
|
snapshot: self,
|
||||||
|
@ -1075,7 +1073,7 @@ impl InlaySnapshot {
|
||||||
|
|
||||||
#[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()
|
||||||
}
|
}
|
||||||
|
@ -1123,7 +1121,7 @@ fn push_isomorphic(sum_tree: &mut SumTree<Transform>, summary: TextSummary) {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{InlayId, MultiBuffer};
|
use crate::{display_map::TextHighlights, 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,7 +1617,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut highlights = TextHighlights::default();
|
let mut text_highlights = TextHighlights::default();
|
||||||
let highlight_count = rng.gen_range(0_usize..10);
|
let highlight_count = rng.gen_range(0_usize..10);
|
||||||
let mut highlight_ranges = (0..highlight_count)
|
let mut highlight_ranges = (0..highlight_count)
|
||||||
.map(|_| buffer_snapshot.random_byte_range(0, &mut rng))
|
.map(|_| buffer_snapshot.random_byte_range(0, &mut rng))
|
||||||
|
@ -1634,7 +1632,7 @@ mod tests {
|
||||||
..buffer_snapshot.anchor_after(range.end)
|
..buffer_snapshot.anchor_after(range.end)
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
highlights.insert(
|
text_highlights.insert(
|
||||||
Some(TypeId::of::<()>()),
|
Some(TypeId::of::<()>()),
|
||||||
Arc::new((HighlightStyle::default(), highlight_ranges)),
|
Arc::new((HighlightStyle::default(), highlight_ranges)),
|
||||||
);
|
);
|
||||||
|
@ -1649,9 +1647,12 @@ mod tests {
|
||||||
.chunks(
|
.chunks(
|
||||||
InlayOffset(start)..InlayOffset(end),
|
InlayOffset(start)..InlayOffset(end),
|
||||||
false,
|
false,
|
||||||
Some(&highlights),
|
Highlights {
|
||||||
None,
|
text_highlights: Some(&text_highlights),
|
||||||
None,
|
inlay_highlights: None,
|
||||||
|
inlay_highlight_style: None,
|
||||||
|
suggestion_highlight_style: None,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
.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!(
|
||||||
|
|
|
@ -7234,7 +7234,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 {
|
||||||
|
@ -8038,11 +8038,11 @@ impl Editor {
|
||||||
self.display_map.read(cx).text_highlights(TypeId::of::<T>())
|
self.display_map.read(cx).text_highlights(TypeId::of::<T>())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn clear_text_highlights<T: 'static>(&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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8683,7 +8683,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
|
||||||
|
@ -8756,7 +8756,7 @@ impl View for Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -444,7 +444,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()
|
||||||
|
@ -545,7 +545,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(
|
||||||
|
@ -1198,7 +1198,7 @@ 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();
|
||||||
|
|
||||||
|
@ -1233,7 +1233,7 @@ 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();
|
||||||
|
|
||||||
|
|
|
@ -236,7 +236,7 @@ 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()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue