Unify text and inlay highlights

This commit is contained in:
Kirill Bulatov 2023-08-22 22:38:49 +03:00
parent 420f8b7b15
commit 12ffbe54fb
9 changed files with 76 additions and 163 deletions

View file

@ -1,6 +1,6 @@
use super::{
fold_map::{self, FoldChunks, FoldEdit, FoldPoint, FoldSnapshot},
InlayHighlights, TextHighlights,
TextHighlights,
};
use crate::MultiBufferSnapshot;
use gpui::fonts::HighlightStyle;
@ -71,7 +71,6 @@ impl TabMap {
None,
None,
None,
None,
) {
for (ix, _) in chunk.text.match_indices('\t') {
let offset_from_edit = offset_from_edit + (ix as u32);
@ -184,7 +183,7 @@ impl TabSnapshot {
self.max_point()
};
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())
{
if c == '\n' {
@ -204,7 +203,6 @@ impl TabSnapshot {
None,
None,
None,
None,
)
.flat_map(|chunk| chunk.text.chars())
{
@ -225,9 +223,8 @@ impl TabSnapshot {
&'a self,
range: Range<TabPoint>,
language_aware: bool,
// TODO kb extract into one struct
// TODO kb extract into one struct?
text_highlights: Option<&'a TextHighlights>,
inlay_highlights: Option<&'a InlayHighlights>,
inlay_highlight_style: Option<HighlightStyle>,
suggestion_highlight_style: Option<HighlightStyle>,
) -> TabChunks<'a> {
@ -250,7 +247,6 @@ impl TabSnapshot {
input_start..input_end,
language_aware,
text_highlights,
inlay_highlights,
inlay_highlight_style,
suggestion_highlight_style,
),
@ -275,16 +271,9 @@ impl TabSnapshot {
#[cfg(test)]
pub fn text(&self) -> String {
self.chunks(
TabPoint::zero()..self.max_point(),
false,
None,
None,
None,
None,
)
.map(|chunk| chunk.text)
.collect()
self.chunks(TabPoint::zero()..self.max_point(), false, None, None, None)
.map(|chunk| chunk.text)
.collect()
}
pub fn max_point(&self) -> TabPoint {
@ -612,7 +601,6 @@ mod tests {
None,
None,
None,
None,
)
.map(|c| c.text)
.collect::<String>(),
@ -687,8 +675,7 @@ 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, None)
{
for chunk in snapshot.chunks(start..snapshot.max_point(), false, None, None, None) {
if chunk.is_tab != was_tab {
if !text.is_empty() {
chunks.push((mem::take(&mut text), was_tab));
@ -757,7 +744,7 @@ mod tests {
let expected_summary = TextSummary::from(expected_text.as_str());
assert_eq!(
tabs_snapshot
.chunks(start..end, false, None, None, None, None)
.chunks(start..end, false, None, None, None)
.map(|c| c.text)
.collect::<String>(),
expected_text,