Remove theme parameters from buffer/display map's chunks methods
Change Chunks to contain highlight ids instead of actual highlight styles. Retrieve the actual highlight style from the theme in the editor element layer. This is to set us up to perform syntax highlighting in other code paths where the theme is not available.
This commit is contained in:
@@ -15,7 +15,6 @@ use std::{
|
||||
};
|
||||
use sum_tree::{Bias, SumTree};
|
||||
use text::{Edit, Point};
|
||||
use theme::SyntaxTheme;
|
||||
|
||||
const NEWLINES: &'static [u8] = &[b'\n'; u8::MAX as usize];
|
||||
|
||||
@@ -461,16 +460,12 @@ impl<'a> BlockMapWriter<'a> {
|
||||
impl BlockSnapshot {
|
||||
#[cfg(test)]
|
||||
pub fn text(&self) -> String {
|
||||
self.chunks(0..self.transforms.summary().output_rows, None)
|
||||
self.chunks(0..self.transforms.summary().output_rows)
|
||||
.map(|chunk| chunk.text)
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn chunks<'a>(
|
||||
&'a self,
|
||||
rows: Range<u32>,
|
||||
theme: Option<&'a SyntaxTheme>,
|
||||
) -> BlockChunks<'a> {
|
||||
pub fn chunks<'a>(&'a self, rows: Range<u32>) -> BlockChunks<'a> {
|
||||
let max_output_row = cmp::min(rows.end, self.transforms.summary().output_rows);
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>();
|
||||
let input_end = {
|
||||
@@ -498,7 +493,7 @@ impl BlockSnapshot {
|
||||
cursor.start().1 .0 + overshoot
|
||||
};
|
||||
BlockChunks {
|
||||
input_chunks: self.wrap_snapshot.chunks(input_start..input_end, theme),
|
||||
input_chunks: self.wrap_snapshot.chunks(input_start..input_end),
|
||||
input_chunk: Default::default(),
|
||||
transforms: cursor,
|
||||
output_row: rows.start,
|
||||
@@ -715,7 +710,7 @@ impl<'a> Iterator for BlockChunks<'a> {
|
||||
|
||||
return Some(Chunk {
|
||||
text: unsafe { std::str::from_utf8_unchecked(&NEWLINES[..line_count as usize]) },
|
||||
highlight_style: None,
|
||||
highlight_id: None,
|
||||
diagnostic: None,
|
||||
});
|
||||
}
|
||||
@@ -1340,7 +1335,7 @@ mod tests {
|
||||
for start_row in 0..expected_row_count {
|
||||
let expected_text = expected_lines[start_row..].join("\n");
|
||||
let actual_text = blocks_snapshot
|
||||
.chunks(start_row as u32..expected_row_count as u32, None)
|
||||
.chunks(start_row as u32..expected_row_count as u32)
|
||||
.map(|chunk| chunk.text)
|
||||
.collect::<String>();
|
||||
assert_eq!(
|
||||
|
||||
@@ -11,7 +11,6 @@ use std::{
|
||||
sync::atomic::{AtomicUsize, Ordering::SeqCst},
|
||||
};
|
||||
use sum_tree::{Bias, Cursor, FilterCursor, SumTree};
|
||||
use theme::SyntaxTheme;
|
||||
|
||||
pub trait ToFoldPoint {
|
||||
fn to_fold_point(&self, snapshot: &FoldSnapshot, bias: Bias) -> FoldPoint;
|
||||
@@ -490,7 +489,7 @@ impl FoldSnapshot {
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn text(&self) -> String {
|
||||
self.chunks(FoldOffset(0)..self.len(), None)
|
||||
self.chunks(FoldOffset(0)..self.len())
|
||||
.map(|c| c.text)
|
||||
.collect()
|
||||
}
|
||||
@@ -630,15 +629,11 @@ impl FoldSnapshot {
|
||||
|
||||
pub fn chars_at(&self, start: FoldPoint) -> impl '_ + Iterator<Item = char> {
|
||||
let start = start.to_offset(self);
|
||||
self.chunks(start..self.len(), None)
|
||||
self.chunks(start..self.len())
|
||||
.flat_map(|chunk| chunk.text.chars())
|
||||
}
|
||||
|
||||
pub fn chunks<'a>(
|
||||
&'a self,
|
||||
range: Range<FoldOffset>,
|
||||
theme: Option<&'a SyntaxTheme>,
|
||||
) -> FoldChunks<'a> {
|
||||
pub fn chunks<'a>(&'a self, range: Range<FoldOffset>) -> FoldChunks<'a> {
|
||||
let mut transform_cursor = self.transforms.cursor::<(FoldOffset, usize)>();
|
||||
|
||||
transform_cursor.seek(&range.end, Bias::Right, &());
|
||||
@@ -651,7 +646,7 @@ impl FoldSnapshot {
|
||||
|
||||
FoldChunks {
|
||||
transform_cursor,
|
||||
buffer_chunks: self.buffer_snapshot.chunks(buffer_start..buffer_end, theme),
|
||||
buffer_chunks: self.buffer_snapshot.chunks(buffer_start..buffer_end),
|
||||
buffer_chunk: None,
|
||||
buffer_offset: buffer_start,
|
||||
output_offset: range.start.0,
|
||||
@@ -976,7 +971,7 @@ impl<'a> Iterator for FoldChunks<'a> {
|
||||
self.output_offset += output_text.len();
|
||||
return Some(Chunk {
|
||||
text: output_text,
|
||||
highlight_style: None,
|
||||
highlight_id: None,
|
||||
diagnostic: None,
|
||||
});
|
||||
}
|
||||
@@ -1398,7 +1393,7 @@ mod tests {
|
||||
let text = &expected_text[start.0..end.0];
|
||||
assert_eq!(
|
||||
snapshot
|
||||
.chunks(start..end, None)
|
||||
.chunks(start..end)
|
||||
.map(|c| c.text)
|
||||
.collect::<String>(),
|
||||
text,
|
||||
|
||||
@@ -5,7 +5,6 @@ use parking_lot::Mutex;
|
||||
use std::{cmp, mem, ops::Range};
|
||||
use sum_tree::Bias;
|
||||
use text::Point;
|
||||
use theme::SyntaxTheme;
|
||||
|
||||
pub struct TabMap(Mutex<TabSnapshot>);
|
||||
|
||||
@@ -35,7 +34,7 @@ impl TabMap {
|
||||
let mut delta = 0;
|
||||
for chunk in old_snapshot
|
||||
.fold_snapshot
|
||||
.chunks(fold_edit.old.end..max_offset, None)
|
||||
.chunks(fold_edit.old.end..max_offset)
|
||||
{
|
||||
let patterns: &[_] = &['\t', '\n'];
|
||||
if let Some(ix) = chunk.text.find(patterns) {
|
||||
@@ -110,7 +109,7 @@ impl TabSnapshot {
|
||||
self.max_point()
|
||||
};
|
||||
for c in self
|
||||
.chunks(range.start..line_end, None)
|
||||
.chunks(range.start..line_end)
|
||||
.flat_map(|chunk| chunk.text.chars())
|
||||
{
|
||||
if c == '\n' {
|
||||
@@ -124,7 +123,7 @@ impl TabSnapshot {
|
||||
last_line_chars = first_line_chars;
|
||||
} else {
|
||||
for _ in self
|
||||
.chunks(TabPoint::new(range.end.row(), 0)..range.end, None)
|
||||
.chunks(TabPoint::new(range.end.row(), 0)..range.end)
|
||||
.flat_map(|chunk| chunk.text.chars())
|
||||
{
|
||||
last_line_chars += 1;
|
||||
@@ -144,11 +143,7 @@ impl TabSnapshot {
|
||||
self.fold_snapshot.version
|
||||
}
|
||||
|
||||
pub fn chunks<'a>(
|
||||
&'a self,
|
||||
range: Range<TabPoint>,
|
||||
theme: Option<&'a SyntaxTheme>,
|
||||
) -> TabChunks<'a> {
|
||||
pub fn chunks<'a>(&'a self, range: Range<TabPoint>) -> TabChunks<'a> {
|
||||
let (input_start, expanded_char_column, to_next_stop) =
|
||||
self.to_fold_point(range.start, Bias::Left);
|
||||
let input_start = input_start.to_offset(&self.fold_snapshot);
|
||||
@@ -163,7 +158,7 @@ impl TabSnapshot {
|
||||
};
|
||||
|
||||
TabChunks {
|
||||
fold_chunks: self.fold_snapshot.chunks(input_start..input_end, theme),
|
||||
fold_chunks: self.fold_snapshot.chunks(input_start..input_end),
|
||||
column: expanded_char_column,
|
||||
output_position: range.start.0,
|
||||
max_output_position: range.end.0,
|
||||
@@ -182,7 +177,7 @@ impl TabSnapshot {
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn text(&self) -> String {
|
||||
self.chunks(TabPoint::zero()..self.max_point(), None)
|
||||
self.chunks(TabPoint::zero()..self.max_point())
|
||||
.map(|chunk| chunk.text)
|
||||
.collect()
|
||||
}
|
||||
@@ -495,7 +490,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
expected_text,
|
||||
tabs_snapshot
|
||||
.chunks(start..end, None)
|
||||
.chunks(start..end)
|
||||
.map(|c| c.text)
|
||||
.collect::<String>(),
|
||||
"chunks({:?}..{:?})",
|
||||
|
||||
@@ -13,7 +13,6 @@ use smol::future::yield_now;
|
||||
use std::{cmp, collections::VecDeque, mem, ops::Range, time::Duration};
|
||||
use sum_tree::{Bias, Cursor, SumTree};
|
||||
use text::Patch;
|
||||
use theme::SyntaxTheme;
|
||||
|
||||
pub use super::tab_map::TextSummary;
|
||||
pub type WrapEdit = text::Edit<u32>;
|
||||
@@ -434,10 +433,8 @@ impl WrapSnapshot {
|
||||
|
||||
let mut line = String::new();
|
||||
let mut remaining = None;
|
||||
let mut chunks = new_tab_snapshot.chunks(
|
||||
TabPoint::new(edit.new_rows.start, 0)..new_tab_snapshot.max_point(),
|
||||
None,
|
||||
);
|
||||
let mut chunks = new_tab_snapshot
|
||||
.chunks(TabPoint::new(edit.new_rows.start, 0)..new_tab_snapshot.max_point());
|
||||
let mut edit_transforms = Vec::<Transform>::new();
|
||||
for _ in edit.new_rows.start..edit.new_rows.end {
|
||||
while let Some(chunk) =
|
||||
@@ -562,15 +559,11 @@ impl WrapSnapshot {
|
||||
}
|
||||
|
||||
pub fn text_chunks(&self, wrap_row: u32) -> impl Iterator<Item = &str> {
|
||||
self.chunks(wrap_row..self.max_point().row() + 1, None)
|
||||
self.chunks(wrap_row..self.max_point().row() + 1)
|
||||
.map(|h| h.text)
|
||||
}
|
||||
|
||||
pub fn chunks<'a>(
|
||||
&'a self,
|
||||
rows: Range<u32>,
|
||||
theme: Option<&'a SyntaxTheme>,
|
||||
) -> WrapChunks<'a> {
|
||||
pub fn chunks<'a>(&'a self, rows: Range<u32>) -> WrapChunks<'a> {
|
||||
let output_start = WrapPoint::new(rows.start, 0);
|
||||
let output_end = WrapPoint::new(rows.end, 0);
|
||||
let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>();
|
||||
@@ -583,7 +576,7 @@ impl WrapSnapshot {
|
||||
.to_tab_point(output_end)
|
||||
.min(self.tab_snapshot.max_point());
|
||||
WrapChunks {
|
||||
input_chunks: self.tab_snapshot.chunks(input_start..input_end, theme),
|
||||
input_chunks: self.tab_snapshot.chunks(input_start..input_end),
|
||||
input_chunk: Default::default(),
|
||||
output_position: output_start,
|
||||
max_output_row: rows.end,
|
||||
@@ -1295,7 +1288,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let actual_text = self
|
||||
.chunks(start_row..end_row, None)
|
||||
.chunks(start_row..end_row)
|
||||
.map(|c| c.text)
|
||||
.collect::<String>();
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user