Unify highlights in *Map

This commit is contained in:
Kirill Bulatov committed 2023-09-14 22:08:12 +03:00
1 parent 5a9d375f79
commit c8ede63d7c
10 files changed
+100 -118

No files matched your search

+6 -14
View File
@@ -1,10 +1,10 @@
use super::{
wrap_map::{self, WrapEdit, WrapPoint, WrapSnapshot},
TextHighlights,
Highlights,
};
use crate::{Anchor, Editor, ExcerptId, ExcerptRange, ToPoint as _};
use collections::{Bound, HashMap, HashSet};
use gpui::{fonts::HighlightStyle, AnyElement, ViewContext};
use gpui::{AnyElement, ViewContext};
use language::{BufferSnapshot, Chunk, Patch, Point};
use parking_lot::Mutex;
use std::{
@@ -576,9 +576,7 @@ impl BlockSnapshot {
self.chunks(
0..self.transforms.summary().output_rows,
false,
None,
None,
None,
Highlights::default(),
)
.map(|chunk| chunk.text)
.collect()
@@ -588,9 +586,7 @@ impl BlockSnapshot {
&'a self,
rows: Range<u32>,
language_aware: bool,
text_highlights: Option<&'a TextHighlights>,
hint_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
highlights: Highlights<'a>,
) -> BlockChunks<'a> {
let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows);
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
@@ -622,9 +618,7 @@ impl BlockSnapshot {
input_chunks: self.wrap_snapshot.chunks(
input_start..input_end,
language_aware,
text_highlights,
hint_highlight_style,
suggestion_highlight_style,
highlights,
),
input_chunk: Default::default(),
transforms: cursor,
@@ -1501,9 +1495,7 @@ mod tests {
.chunks(
start_row as u32..blocks_snapshot.max_point().row + 1,
false,
None,
None,
None,
Highlights::default(),
)
.map(|chunk| chunk.text)
.collect::<String>();
+11 -11
View File
@@ -1,6 +1,6 @@
use super::{
inlay_map::{InlayBufferRows, InlayChunks, InlayEdit, InlayOffset, InlayPoint, InlaySnapshot},
TextHighlights,
Highlights,
};
use crate::{Anchor, AnchorRangeExt, MultiBufferSnapshot, ToOffset};
use gpui::{color::Color, fonts::HighlightStyle};
@@ -475,7 +475,7 @@ pub struct FoldSnapshot {
impl FoldSnapshot {
#[cfg(test)]
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)
.collect()
}
@@ -651,9 +651,7 @@ impl FoldSnapshot {
&'a self,
range: Range<FoldOffset>,
language_aware: bool,
text_highlights: Option<&'a TextHighlights>,
hint_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
highlights: Highlights<'a>,
) -> FoldChunks<'a> {
let mut transform_cursor = self.transforms.cursor::<(FoldOffset, InlayOffset)>();
@@ -674,9 +672,7 @@ impl FoldSnapshot {
inlay_chunks: self.inlay_snapshot.chunks(
inlay_start..inlay_end,
language_aware,
text_highlights,
hint_highlight_style,
suggestion_highlight_style,
highlights,
),
inlay_chunk: None,
inlay_offset: inlay_start,
@@ -687,8 +683,12 @@ impl FoldSnapshot {
}
pub fn chars_at(&self, start: FoldPoint) -> impl '_ + Iterator<Item = char> {
self.chunks(start.to_offset(self)..self.len(), false, None, None, None)
.flat_map(|chunk| chunk.text.chars())
self.chunks(
start.to_offset(self)..self.len(),
false,
Highlights::default(),
)
.flat_map(|chunk| chunk.text.chars())
}
#[cfg(test)]
@@ -1496,7 +1496,7 @@ mod tests {
let text = &expected_text[start.0..end.0];
assert_eq!(
snapshot
.chunks(start..end, false, None, None, None)
.chunks(start..end, false, Highlights::default())
.map(|c| c.text)
.collect::<String>(),
text,
+17 -16
View File
@@ -15,7 +15,7 @@ use std::{
use sum_tree::{Bias, Cursor, SumTree};
use text::{Patch, Rope};
use super::TextHighlights;
use super::Highlights;
pub struct InlayMap {
snapshot: InlaySnapshot,
@@ -213,7 +213,7 @@ pub struct InlayChunks<'a> {
inlay_chunk: Option<&'a str>,
output_offset: InlayOffset,
max_output_offset: InlayOffset,
hint_highlight_style: Option<HighlightStyle>,
inlay_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
highlight_endpoints: Peekable<vec::IntoIter<HighlightEndpoint>>,
active_highlights: BTreeMap<Option<TypeId>, HighlightStyle>,
@@ -314,7 +314,7 @@ impl<'a> Iterator for InlayChunks<'a> {
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,
InlayId::Hint(_) => self.inlay_highlight_style,
};
if !self.active_highlights.is_empty() {
for active_highlight in self.active_highlights.values() {
@@ -991,15 +991,13 @@ impl InlaySnapshot {
&'a self,
range: Range<InlayOffset>,
language_aware: bool,
text_highlights: Option<&'a TextHighlights>,
hint_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
highlights: Highlights<'a>,
) -> InlayChunks<'a> {
let mut cursor = self.transforms.cursor::<(InlayOffset, usize)>();
cursor.seek(&range.start, Bias::Right, &());
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() {
while cursor.start().0 < range.end {
let transform_start = self.buffer.anchor_after(
@@ -1065,8 +1063,8 @@ impl InlaySnapshot {
buffer_chunk: None,
output_offset: range.start,
max_output_offset: range.end,
hint_highlight_style,
suggestion_highlight_style,
inlay_highlight_style: highlights.inlay_highlight_style,
suggestion_highlight_style: highlights.suggestion_highlight_style,
highlight_endpoints: highlight_endpoints.into_iter().peekable(),
active_highlights: Default::default(),
snapshot: self,
@@ -1075,7 +1073,7 @@ impl InlaySnapshot {
#[cfg(test)]
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)
.collect()
}
@@ -1123,7 +1121,7 @@ fn push_isomorphic(sum_tree: &mut SumTree<Transform>, summary: TextSummary) {
#[cfg(test)]
mod tests {
use super::*;
use crate::{InlayId, MultiBuffer};
use crate::{display_map::TextHighlights, InlayId, MultiBuffer};
use gpui::AppContext;
use project::{InlayHint, InlayHintLabel, ResolveState};
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 mut highlight_ranges = (0..highlight_count)
.map(|_| buffer_snapshot.random_byte_range(0, &mut rng))
@@ -1634,7 +1632,7 @@ mod tests {
..buffer_snapshot.anchor_after(range.end)
})
.collect::<Vec<_>>();
highlights.insert(
text_highlights.insert(
Some(TypeId::of::<()>()),
Arc::new((HighlightStyle::default(), highlight_ranges)),
);
@@ -1649,9 +1647,12 @@ mod tests {
.chunks(
InlayOffset(start)..InlayOffset(end),
false,
Some(&highlights),
None,
None,
Highlights {
text_highlights: Some(&text_highlights),
inlay_highlights: None,
inlay_highlight_style: None,
suggestion_highlight_style: None,
},
)
.map(|chunk| chunk.text)
.collect::<String>();
+17 -23
View File
@@ -1,9 +1,8 @@
use super::{
fold_map::{self, FoldChunks, FoldEdit, FoldPoint, FoldSnapshot},
TextHighlights,
Highlights,
};
use crate::MultiBufferSnapshot;
use gpui::fonts::HighlightStyle;
use language::{Chunk, Point};
use std::{cmp, mem, num::NonZeroU32, ops::Range};
use sum_tree::Bias;
@@ -68,9 +67,7 @@ impl TabMap {
'outer: for chunk in old_snapshot.fold_snapshot.chunks(
fold_edit.old.end..old_end_row_successor_offset,
false,
None,
None,
None,
Highlights::default(),
) {
for (ix, _) in chunk.text.match_indices('\t') {
let offset_from_edit = offset_from_edit + (ix as u32);
@@ -183,7 +180,7 @@ impl TabSnapshot {
self.max_point()
};
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())
{
if c == '\n' {
@@ -200,9 +197,7 @@ impl TabSnapshot {
.chunks(
TabPoint::new(range.end.row(), 0)..range.end,
false,
None,
None,
None,
Highlights::default(),
)
.flat_map(|chunk| chunk.text.chars())
{
@@ -223,9 +218,7 @@ impl TabSnapshot {
&'a self,
range: Range<TabPoint>,
language_aware: bool,
text_highlights: Option<&'a TextHighlights>,
hint_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
highlights: Highlights<'a>,
) -> TabChunks<'a> {
let (input_start, expanded_char_column, to_next_stop) =
self.to_fold_point(range.start, Bias::Left);
@@ -245,9 +238,7 @@ impl TabSnapshot {
fold_chunks: self.fold_snapshot.chunks(
input_start..input_end,
language_aware,
text_highlights,
hint_highlight_style,
suggestion_highlight_style,
highlights,
),
input_column,
column: expanded_char_column,
@@ -270,9 +261,13 @@ impl TabSnapshot {
#[cfg(test)]
pub fn text(&self) -> String {
self.chunks(TabPoint::zero()..self.max_point(), false, None, None, None)
.map(|chunk| chunk.text)
.collect()
self.chunks(
TabPoint::zero()..self.max_point(),
false,
Highlights::default(),
)
.map(|chunk| chunk.text)
.collect()
}
pub fn max_point(&self) -> TabPoint {
@@ -597,9 +592,7 @@ mod tests {
.chunks(
TabPoint::new(0, ix as u32)..tab_snapshot.max_point(),
false,
None,
None,
None,
Highlights::default(),
)
.map(|c| c.text)
.collect::<String>(),
@@ -674,7 +667,8 @@ mod tests {
let mut chunks = Vec::new();
let mut was_tab = false;
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 !text.is_empty() {
chunks.push((mem::take(&mut text), was_tab));
@@ -743,7 +737,7 @@ mod tests {
let expected_summary = TextSummary::from(expected_text.as_str());
assert_eq!(
tabs_snapshot
.chunks(start..end, false, None, None, None)
.chunks(start..end, false, Highlights::default())
.map(|c| c.text)
.collect::<String>(),
expected_text,
+7 -17
View File
@@ -1,13 +1,11 @@
use super::{
fold_map::FoldBufferRows,
tab_map::{self, TabEdit, TabPoint, TabSnapshot},
TextHighlights,
Highlights,
};
use crate::MultiBufferSnapshot;
use gpui::{
fonts::{FontId, HighlightStyle},
text_layout::LineWrapper,
AppContext, Entity, ModelContext, ModelHandle, Task,
fonts::FontId, text_layout::LineWrapper, AppContext, Entity, ModelContext, ModelHandle, Task,
};
use language::{Chunk, Point};
use lazy_static::lazy_static;
@@ -444,9 +442,7 @@ impl WrapSnapshot {
let mut chunks = new_tab_snapshot.chunks(
TabPoint::new(edit.new_rows.start, 0)..new_tab_snapshot.max_point(),
false,
None,
None,
None,
Highlights::default(),
);
let mut edit_transforms = Vec::<Transform>::new();
for _ in edit.new_rows.start..edit.new_rows.end {
@@ -575,9 +571,7 @@ impl WrapSnapshot {
&'a self,
rows: Range<u32>,
language_aware: bool,
text_highlights: Option<&'a TextHighlights>,
hint_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
highlights: Highlights<'a>,
) -> WrapChunks<'a> {
let output_start = WrapPoint::new(rows.start, 0);
let output_end = WrapPoint::new(rows.end, 0);
@@ -594,9 +588,7 @@ impl WrapSnapshot {
input_chunks: self.tab_snapshot.chunks(
input_start..input_end,
language_aware,
text_highlights,
hint_highlight_style,
suggestion_highlight_style,
highlights,
),
input_chunk: Default::default(),
output_position: output_start,
@@ -1323,9 +1315,7 @@ mod tests {
self.chunks(
wrap_row..self.max_point().row() + 1,
false,
None,
None,
None,
Highlights::default(),
)
.map(|h| h.text)
}
@@ -1350,7 +1340,7 @@ mod tests {
}
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)
.collect::<String>();
assert_eq!(