sum_tree: Do not implement Dimension on tuples, use new Dimensions wrapper instead (#35482)
This is a bit of a readability improvement IMHO; I often find myself confused when dealing when dimension pairs, as there's no easy way to jump to the implementation of a dimension for tuples to remind myself for the n-th time how exactly that impl works. Now it should be possible to jump directly to that impl. Another bonus is that Dimension supports 3-ary tuples as well - by using a () as a default value of a 3rd dimension. Release Notes: - N/A
This commit is contained in:
parent
be2f54b233
commit
07e3d53d58
18 changed files with 215 additions and 141 deletions
|
@ -22,7 +22,7 @@ use std::{
|
|||
atomic::{AtomicUsize, Ordering::SeqCst},
|
||||
},
|
||||
};
|
||||
use sum_tree::{Bias, SumTree, Summary, TreeMap};
|
||||
use sum_tree::{Bias, Dimensions, SumTree, Summary, TreeMap};
|
||||
use text::{BufferId, Edit};
|
||||
use ui::ElementId;
|
||||
|
||||
|
@ -416,7 +416,7 @@ struct TransformSummary {
|
|||
}
|
||||
|
||||
pub struct BlockChunks<'a> {
|
||||
transforms: sum_tree::Cursor<'a, Transform, (BlockRow, WrapRow)>,
|
||||
transforms: sum_tree::Cursor<'a, Transform, Dimensions<BlockRow, WrapRow>>,
|
||||
input_chunks: wrap_map::WrapChunks<'a>,
|
||||
input_chunk: Chunk<'a>,
|
||||
output_row: u32,
|
||||
|
@ -426,7 +426,7 @@ pub struct BlockChunks<'a> {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct BlockRows<'a> {
|
||||
transforms: sum_tree::Cursor<'a, Transform, (BlockRow, WrapRow)>,
|
||||
transforms: sum_tree::Cursor<'a, Transform, Dimensions<BlockRow, WrapRow>>,
|
||||
input_rows: wrap_map::WrapRows<'a>,
|
||||
output_row: BlockRow,
|
||||
started: bool,
|
||||
|
@ -970,7 +970,7 @@ impl BlockMapReader<'_> {
|
|||
.unwrap_or(self.wrap_snapshot.max_point().row() + 1),
|
||||
);
|
||||
|
||||
let mut cursor = self.transforms.cursor::<(WrapRow, BlockRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(&());
|
||||
cursor.seek(&start_wrap_row, Bias::Left);
|
||||
while let Some(transform) = cursor.item() {
|
||||
if cursor.start().0 > end_wrap_row {
|
||||
|
@ -1292,7 +1292,7 @@ impl BlockSnapshot {
|
|||
) -> BlockChunks<'a> {
|
||||
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::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
cursor.seek(&BlockRow(rows.start), Bias::Right);
|
||||
let transform_output_start = cursor.start().0.0;
|
||||
let transform_input_start = cursor.start().1.0;
|
||||
|
@ -1324,9 +1324,9 @@ impl BlockSnapshot {
|
|||
}
|
||||
|
||||
pub(super) fn row_infos(&self, start_row: BlockRow) -> BlockRows<'_> {
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
cursor.seek(&start_row, Bias::Right);
|
||||
let (output_start, input_start) = cursor.start();
|
||||
let Dimensions(output_start, input_start, _) = cursor.start();
|
||||
let overshoot = if cursor
|
||||
.item()
|
||||
.map_or(false, |transform| transform.block.is_none())
|
||||
|
@ -1441,14 +1441,14 @@ impl BlockSnapshot {
|
|||
}
|
||||
|
||||
pub fn longest_row_in_range(&self, range: Range<BlockRow>) -> BlockRow {
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
cursor.seek(&range.start, Bias::Right);
|
||||
|
||||
let mut longest_row = range.start;
|
||||
let mut longest_row_chars = 0;
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.block.is_none() {
|
||||
let (output_start, input_start) = cursor.start();
|
||||
let Dimensions(output_start, input_start, _) = cursor.start();
|
||||
let overshoot = range.start.0 - output_start.0;
|
||||
let wrap_start_row = input_start.0 + overshoot;
|
||||
let wrap_end_row = cmp::min(
|
||||
|
@ -1474,7 +1474,7 @@ impl BlockSnapshot {
|
|||
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.block.is_none() {
|
||||
let (output_start, input_start) = cursor.start();
|
||||
let Dimensions(output_start, input_start, _) = cursor.start();
|
||||
let overshoot = range.end.0 - output_start.0;
|
||||
let wrap_start_row = input_start.0;
|
||||
let wrap_end_row = input_start.0 + overshoot;
|
||||
|
@ -1492,10 +1492,10 @@ impl BlockSnapshot {
|
|||
}
|
||||
|
||||
pub(super) fn line_len(&self, row: BlockRow) -> u32 {
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
cursor.seek(&BlockRow(row.0), Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
let (output_start, input_start) = cursor.start();
|
||||
let Dimensions(output_start, input_start, _) = cursor.start();
|
||||
let overshoot = row.0 - output_start.0;
|
||||
if transform.block.is_some() {
|
||||
0
|
||||
|
@ -1510,13 +1510,13 @@ impl BlockSnapshot {
|
|||
}
|
||||
|
||||
pub(super) fn is_block_line(&self, row: BlockRow) -> bool {
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
cursor.seek(&row, Bias::Right);
|
||||
cursor.item().map_or(false, |t| t.block.is_some())
|
||||
}
|
||||
|
||||
pub(super) fn is_folded_buffer_header(&self, row: BlockRow) -> bool {
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
cursor.seek(&row, Bias::Right);
|
||||
let Some(transform) = cursor.item() else {
|
||||
return false;
|
||||
|
@ -1528,7 +1528,7 @@ impl BlockSnapshot {
|
|||
let wrap_point = self
|
||||
.wrap_snapshot
|
||||
.make_wrap_point(Point::new(row.0, 0), Bias::Left);
|
||||
let mut cursor = self.transforms.cursor::<(WrapRow, BlockRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(&());
|
||||
cursor.seek(&WrapRow(wrap_point.row()), Bias::Right);
|
||||
cursor.item().map_or(false, |transform| {
|
||||
transform
|
||||
|
@ -1539,7 +1539,7 @@ impl BlockSnapshot {
|
|||
}
|
||||
|
||||
pub fn clip_point(&self, point: BlockPoint, bias: Bias) -> BlockPoint {
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
cursor.seek(&BlockRow(point.row), Bias::Right);
|
||||
|
||||
let max_input_row = WrapRow(self.transforms.summary().input_rows);
|
||||
|
@ -1549,8 +1549,8 @@ impl BlockSnapshot {
|
|||
|
||||
loop {
|
||||
if let Some(transform) = cursor.item() {
|
||||
let (output_start_row, input_start_row) = cursor.start();
|
||||
let (output_end_row, input_end_row) = cursor.end();
|
||||
let Dimensions(output_start_row, input_start_row, _) = cursor.start();
|
||||
let Dimensions(output_end_row, input_end_row, _) = cursor.end();
|
||||
let output_start = Point::new(output_start_row.0, 0);
|
||||
let input_start = Point::new(input_start_row.0, 0);
|
||||
let input_end = Point::new(input_end_row.0, 0);
|
||||
|
@ -1599,13 +1599,13 @@ impl BlockSnapshot {
|
|||
}
|
||||
|
||||
pub fn to_block_point(&self, wrap_point: WrapPoint) -> BlockPoint {
|
||||
let mut cursor = self.transforms.cursor::<(WrapRow, BlockRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<WrapRow, BlockRow>>(&());
|
||||
cursor.seek(&WrapRow(wrap_point.row()), Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
if transform.block.is_some() {
|
||||
BlockPoint::new(cursor.start().1.0, 0)
|
||||
} else {
|
||||
let (input_start_row, output_start_row) = cursor.start();
|
||||
let Dimensions(input_start_row, output_start_row, _) = cursor.start();
|
||||
let input_start = Point::new(input_start_row.0, 0);
|
||||
let output_start = Point::new(output_start_row.0, 0);
|
||||
let input_overshoot = wrap_point.0 - input_start;
|
||||
|
@ -1617,7 +1617,7 @@ impl BlockSnapshot {
|
|||
}
|
||||
|
||||
pub fn to_wrap_point(&self, block_point: BlockPoint, bias: Bias) -> WrapPoint {
|
||||
let mut cursor = self.transforms.cursor::<(BlockRow, WrapRow)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<BlockRow, WrapRow>>(&());
|
||||
cursor.seek(&BlockRow(block_point.row), Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
match transform.block.as_ref() {
|
||||
|
|
|
@ -17,7 +17,7 @@ use std::{
|
|||
sync::Arc,
|
||||
usize,
|
||||
};
|
||||
use sum_tree::{Bias, Cursor, FilterCursor, SumTree, Summary, TreeMap};
|
||||
use sum_tree::{Bias, Cursor, Dimensions, FilterCursor, SumTree, Summary, TreeMap};
|
||||
use ui::IntoElement as _;
|
||||
use util::post_inc;
|
||||
|
||||
|
@ -98,7 +98,9 @@ impl FoldPoint {
|
|||
}
|
||||
|
||||
pub fn to_inlay_point(self, snapshot: &FoldSnapshot) -> InlayPoint {
|
||||
let mut cursor = snapshot.transforms.cursor::<(FoldPoint, InlayPoint)>(&());
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(&());
|
||||
cursor.seek(&self, Bias::Right);
|
||||
let overshoot = self.0 - cursor.start().0.0;
|
||||
InlayPoint(cursor.start().1.0 + overshoot)
|
||||
|
@ -107,7 +109,7 @@ impl FoldPoint {
|
|||
pub fn to_offset(self, snapshot: &FoldSnapshot) -> FoldOffset {
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<(FoldPoint, TransformSummary)>(&());
|
||||
.cursor::<Dimensions<FoldPoint, TransformSummary>>(&());
|
||||
cursor.seek(&self, Bias::Right);
|
||||
let overshoot = self.0 - cursor.start().1.output.lines;
|
||||
let mut offset = cursor.start().1.output.len;
|
||||
|
@ -567,8 +569,9 @@ impl FoldMap {
|
|||
let mut old_transforms = self
|
||||
.snapshot
|
||||
.transforms
|
||||
.cursor::<(InlayOffset, FoldOffset)>(&());
|
||||
let mut new_transforms = new_transforms.cursor::<(InlayOffset, FoldOffset)>(&());
|
||||
.cursor::<Dimensions<InlayOffset, FoldOffset>>(&());
|
||||
let mut new_transforms =
|
||||
new_transforms.cursor::<Dimensions<InlayOffset, FoldOffset>>(&());
|
||||
|
||||
for mut edit in inlay_edits {
|
||||
old_transforms.seek(&edit.old.start, Bias::Left);
|
||||
|
@ -651,7 +654,9 @@ impl FoldSnapshot {
|
|||
pub fn text_summary_for_range(&self, range: Range<FoldPoint>) -> TextSummary {
|
||||
let mut summary = TextSummary::default();
|
||||
|
||||
let mut cursor = self.transforms.cursor::<(FoldPoint, InlayPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(&());
|
||||
cursor.seek(&range.start, Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
let start_in_transform = range.start.0 - cursor.start().0.0;
|
||||
|
@ -700,7 +705,9 @@ impl FoldSnapshot {
|
|||
}
|
||||
|
||||
pub fn to_fold_point(&self, point: InlayPoint, bias: Bias) -> FoldPoint {
|
||||
let mut cursor = self.transforms.cursor::<(InlayPoint, FoldPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayPoint, FoldPoint>>(&());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
if cursor.item().map_or(false, |t| t.is_fold()) {
|
||||
if bias == Bias::Left || point == cursor.start().0 {
|
||||
|
@ -734,7 +741,9 @@ impl FoldSnapshot {
|
|||
}
|
||||
|
||||
let fold_point = FoldPoint::new(start_row, 0);
|
||||
let mut cursor = self.transforms.cursor::<(FoldPoint, InlayPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(&());
|
||||
cursor.seek(&fold_point, Bias::Left);
|
||||
|
||||
let overshoot = fold_point.0 - cursor.start().0.0;
|
||||
|
@ -816,7 +825,9 @@ impl FoldSnapshot {
|
|||
language_aware: bool,
|
||||
highlights: Highlights<'a>,
|
||||
) -> FoldChunks<'a> {
|
||||
let mut transform_cursor = self.transforms.cursor::<(FoldOffset, InlayOffset)>(&());
|
||||
let mut transform_cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldOffset, InlayOffset>>(&());
|
||||
transform_cursor.seek(&range.start, Bias::Right);
|
||||
|
||||
let inlay_start = {
|
||||
|
@ -871,7 +882,9 @@ impl FoldSnapshot {
|
|||
}
|
||||
|
||||
pub fn clip_point(&self, point: FoldPoint, bias: Bias) -> FoldPoint {
|
||||
let mut cursor = self.transforms.cursor::<(FoldPoint, InlayPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldPoint, InlayPoint>>(&());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
let transform_start = cursor.start().0.0;
|
||||
|
@ -1196,7 +1209,7 @@ impl<'a> sum_tree::Dimension<'a, FoldSummary> for usize {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct FoldRows<'a> {
|
||||
cursor: Cursor<'a, Transform, (FoldPoint, InlayPoint)>,
|
||||
cursor: Cursor<'a, Transform, Dimensions<FoldPoint, InlayPoint>>,
|
||||
input_rows: InlayBufferRows<'a>,
|
||||
fold_point: FoldPoint,
|
||||
}
|
||||
|
@ -1313,7 +1326,7 @@ impl DerefMut for ChunkRendererContext<'_, '_> {
|
|||
}
|
||||
|
||||
pub struct FoldChunks<'a> {
|
||||
transform_cursor: Cursor<'a, Transform, (FoldOffset, InlayOffset)>,
|
||||
transform_cursor: Cursor<'a, Transform, Dimensions<FoldOffset, InlayOffset>>,
|
||||
inlay_chunks: InlayChunks<'a>,
|
||||
inlay_chunk: Option<(InlayOffset, InlayChunk<'a>)>,
|
||||
inlay_offset: InlayOffset,
|
||||
|
@ -1448,7 +1461,7 @@ impl FoldOffset {
|
|||
pub fn to_point(self, snapshot: &FoldSnapshot) -> FoldPoint {
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<(FoldOffset, TransformSummary)>(&());
|
||||
.cursor::<Dimensions<FoldOffset, TransformSummary>>(&());
|
||||
cursor.seek(&self, Bias::Right);
|
||||
let overshoot = if cursor.item().map_or(true, |t| t.is_fold()) {
|
||||
Point::new(0, (self.0 - cursor.start().0.0) as u32)
|
||||
|
@ -1462,7 +1475,9 @@ impl FoldOffset {
|
|||
|
||||
#[cfg(test)]
|
||||
pub fn to_inlay_offset(self, snapshot: &FoldSnapshot) -> InlayOffset {
|
||||
let mut cursor = snapshot.transforms.cursor::<(FoldOffset, InlayOffset)>(&());
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<Dimensions<FoldOffset, InlayOffset>>(&());
|
||||
cursor.seek(&self, Bias::Right);
|
||||
let overshoot = self.0 - cursor.start().0.0;
|
||||
InlayOffset(cursor.start().1.0 + overshoot)
|
||||
|
|
|
@ -10,7 +10,7 @@ use std::{
|
|||
ops::{Add, AddAssign, Range, Sub, SubAssign},
|
||||
sync::Arc,
|
||||
};
|
||||
use sum_tree::{Bias, Cursor, SumTree};
|
||||
use sum_tree::{Bias, Cursor, Dimensions, SumTree};
|
||||
use text::{Patch, Rope};
|
||||
use ui::{ActiveTheme, IntoElement as _, ParentElement as _, Styled as _, div};
|
||||
|
||||
|
@ -235,14 +235,14 @@ impl<'a> sum_tree::Dimension<'a, TransformSummary> for Point {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct InlayBufferRows<'a> {
|
||||
transforms: Cursor<'a, Transform, (InlayPoint, Point)>,
|
||||
transforms: Cursor<'a, Transform, Dimensions<InlayPoint, Point>>,
|
||||
buffer_rows: MultiBufferRows<'a>,
|
||||
inlay_row: u32,
|
||||
max_buffer_row: MultiBufferRow,
|
||||
}
|
||||
|
||||
pub struct InlayChunks<'a> {
|
||||
transforms: Cursor<'a, Transform, (InlayOffset, usize)>,
|
||||
transforms: Cursor<'a, Transform, Dimensions<InlayOffset, usize>>,
|
||||
buffer_chunks: CustomHighlightsChunks<'a>,
|
||||
buffer_chunk: Option<Chunk<'a>>,
|
||||
inlay_chunks: Option<text::Chunks<'a>>,
|
||||
|
@ -551,7 +551,9 @@ impl InlayMap {
|
|||
} else {
|
||||
let mut inlay_edits = Patch::default();
|
||||
let mut new_transforms = SumTree::default();
|
||||
let mut cursor = snapshot.transforms.cursor::<(usize, InlayOffset)>(&());
|
||||
let mut cursor = snapshot
|
||||
.transforms
|
||||
.cursor::<Dimensions<usize, InlayOffset>>(&());
|
||||
let mut buffer_edits_iter = buffer_edits.iter().peekable();
|
||||
while let Some(buffer_edit) = buffer_edits_iter.next() {
|
||||
new_transforms.append(cursor.slice(&buffer_edit.old.start, Bias::Left), &());
|
||||
|
@ -770,20 +772,20 @@ impl InlaySnapshot {
|
|||
pub fn to_point(&self, offset: InlayOffset) -> InlayPoint {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<(InlayOffset, (InlayPoint, usize))>(&());
|
||||
.cursor::<Dimensions<InlayOffset, InlayPoint, usize>>(&());
|
||||
cursor.seek(&offset, Bias::Right);
|
||||
let overshoot = offset.0 - cursor.start().0.0;
|
||||
match cursor.item() {
|
||||
Some(Transform::Isomorphic(_)) => {
|
||||
let buffer_offset_start = cursor.start().1.1;
|
||||
let buffer_offset_start = cursor.start().2;
|
||||
let buffer_offset_end = buffer_offset_start + overshoot;
|
||||
let buffer_start = self.buffer.offset_to_point(buffer_offset_start);
|
||||
let buffer_end = self.buffer.offset_to_point(buffer_offset_end);
|
||||
InlayPoint(cursor.start().1.0.0 + (buffer_end - buffer_start))
|
||||
InlayPoint(cursor.start().1.0 + (buffer_end - buffer_start))
|
||||
}
|
||||
Some(Transform::Inlay(inlay)) => {
|
||||
let overshoot = inlay.text.offset_to_point(overshoot);
|
||||
InlayPoint(cursor.start().1.0.0 + overshoot)
|
||||
InlayPoint(cursor.start().1.0 + overshoot)
|
||||
}
|
||||
None => self.max_point(),
|
||||
}
|
||||
|
@ -800,26 +802,26 @@ impl InlaySnapshot {
|
|||
pub fn to_offset(&self, point: InlayPoint) -> InlayOffset {
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<(InlayPoint, (InlayOffset, Point))>(&());
|
||||
.cursor::<Dimensions<InlayPoint, InlayOffset, Point>>(&());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
let overshoot = point.0 - cursor.start().0.0;
|
||||
match cursor.item() {
|
||||
Some(Transform::Isomorphic(_)) => {
|
||||
let buffer_point_start = cursor.start().1.1;
|
||||
let buffer_point_start = cursor.start().2;
|
||||
let buffer_point_end = buffer_point_start + overshoot;
|
||||
let buffer_offset_start = self.buffer.point_to_offset(buffer_point_start);
|
||||
let buffer_offset_end = self.buffer.point_to_offset(buffer_point_end);
|
||||
InlayOffset(cursor.start().1.0.0 + (buffer_offset_end - buffer_offset_start))
|
||||
InlayOffset(cursor.start().1.0 + (buffer_offset_end - buffer_offset_start))
|
||||
}
|
||||
Some(Transform::Inlay(inlay)) => {
|
||||
let overshoot = inlay.text.point_to_offset(overshoot);
|
||||
InlayOffset(cursor.start().1.0.0 + overshoot)
|
||||
InlayOffset(cursor.start().1.0 + overshoot)
|
||||
}
|
||||
None => self.len(),
|
||||
}
|
||||
}
|
||||
pub fn to_buffer_point(&self, point: InlayPoint) -> Point {
|
||||
let mut cursor = self.transforms.cursor::<(InlayPoint, Point)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(&());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
match cursor.item() {
|
||||
Some(Transform::Isomorphic(_)) => {
|
||||
|
@ -831,7 +833,9 @@ impl InlaySnapshot {
|
|||
}
|
||||
}
|
||||
pub fn to_buffer_offset(&self, offset: InlayOffset) -> usize {
|
||||
let mut cursor = self.transforms.cursor::<(InlayOffset, usize)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayOffset, usize>>(&());
|
||||
cursor.seek(&offset, Bias::Right);
|
||||
match cursor.item() {
|
||||
Some(Transform::Isomorphic(_)) => {
|
||||
|
@ -844,7 +848,9 @@ impl InlaySnapshot {
|
|||
}
|
||||
|
||||
pub fn to_inlay_offset(&self, offset: usize) -> InlayOffset {
|
||||
let mut cursor = self.transforms.cursor::<(usize, InlayOffset)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<usize, InlayOffset>>(&());
|
||||
cursor.seek(&offset, Bias::Left);
|
||||
loop {
|
||||
match cursor.item() {
|
||||
|
@ -877,7 +883,7 @@ impl InlaySnapshot {
|
|||
}
|
||||
}
|
||||
pub fn to_inlay_point(&self, point: Point) -> InlayPoint {
|
||||
let mut cursor = self.transforms.cursor::<(Point, InlayPoint)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<Point, InlayPoint>>(&());
|
||||
cursor.seek(&point, Bias::Left);
|
||||
loop {
|
||||
match cursor.item() {
|
||||
|
@ -911,7 +917,7 @@ impl InlaySnapshot {
|
|||
}
|
||||
|
||||
pub fn clip_point(&self, mut point: InlayPoint, mut bias: Bias) -> InlayPoint {
|
||||
let mut cursor = self.transforms.cursor::<(InlayPoint, Point)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(&());
|
||||
cursor.seek(&point, Bias::Left);
|
||||
loop {
|
||||
match cursor.item() {
|
||||
|
@ -1008,7 +1014,9 @@ impl InlaySnapshot {
|
|||
pub fn text_summary_for_range(&self, range: Range<InlayOffset>) -> TextSummary {
|
||||
let mut summary = TextSummary::default();
|
||||
|
||||
let mut cursor = self.transforms.cursor::<(InlayOffset, usize)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayOffset, usize>>(&());
|
||||
cursor.seek(&range.start, Bias::Right);
|
||||
|
||||
let overshoot = range.start.0 - cursor.start().0.0;
|
||||
|
@ -1056,7 +1064,7 @@ impl InlaySnapshot {
|
|||
}
|
||||
|
||||
pub fn row_infos(&self, row: u32) -> InlayBufferRows<'_> {
|
||||
let mut cursor = self.transforms.cursor::<(InlayPoint, Point)>(&());
|
||||
let mut cursor = self.transforms.cursor::<Dimensions<InlayPoint, Point>>(&());
|
||||
let inlay_point = InlayPoint::new(row, 0);
|
||||
cursor.seek(&inlay_point, Bias::Left);
|
||||
|
||||
|
@ -1098,7 +1106,9 @@ impl InlaySnapshot {
|
|||
language_aware: bool,
|
||||
highlights: Highlights<'a>,
|
||||
) -> InlayChunks<'a> {
|
||||
let mut cursor = self.transforms.cursor::<(InlayOffset, usize)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<InlayOffset, usize>>(&());
|
||||
cursor.seek(&range.start, Bias::Right);
|
||||
|
||||
let buffer_range = self.to_buffer_offset(range.start)..self.to_buffer_offset(range.end);
|
||||
|
|
|
@ -9,7 +9,7 @@ use multi_buffer::{MultiBufferSnapshot, RowInfo};
|
|||
use smol::future::yield_now;
|
||||
use std::sync::LazyLock;
|
||||
use std::{cmp, collections::VecDeque, mem, ops::Range, time::Duration};
|
||||
use sum_tree::{Bias, Cursor, SumTree};
|
||||
use sum_tree::{Bias, Cursor, Dimensions, SumTree};
|
||||
use text::Patch;
|
||||
|
||||
pub use super::tab_map::TextSummary;
|
||||
|
@ -55,7 +55,7 @@ pub struct WrapChunks<'a> {
|
|||
input_chunk: Chunk<'a>,
|
||||
output_position: WrapPoint,
|
||||
max_output_row: u32,
|
||||
transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>,
|
||||
transforms: Cursor<'a, Transform, Dimensions<WrapPoint, TabPoint>>,
|
||||
snapshot: &'a WrapSnapshot,
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ pub struct WrapRows<'a> {
|
|||
output_row: u32,
|
||||
soft_wrapped: bool,
|
||||
max_output_row: u32,
|
||||
transforms: Cursor<'a, Transform, (WrapPoint, TabPoint)>,
|
||||
transforms: Cursor<'a, Transform, Dimensions<WrapPoint, TabPoint>>,
|
||||
}
|
||||
|
||||
impl WrapRows<'_> {
|
||||
|
@ -598,7 +598,9 @@ impl WrapSnapshot {
|
|||
) -> 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)>(&());
|
||||
let mut transforms = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
transforms.seek(&output_start, Bias::Right);
|
||||
let mut input_start = TabPoint(transforms.start().1.0);
|
||||
if transforms.item().map_or(false, |t| t.is_isomorphic()) {
|
||||
|
@ -626,7 +628,9 @@ impl WrapSnapshot {
|
|||
}
|
||||
|
||||
pub fn line_len(&self, row: u32) -> u32 {
|
||||
let mut cursor = self.transforms.cursor::<(WrapPoint, TabPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
cursor.seek(&WrapPoint::new(row + 1, 0), Bias::Left);
|
||||
if cursor
|
||||
.item()
|
||||
|
@ -651,7 +655,9 @@ impl WrapSnapshot {
|
|||
let start = WrapPoint::new(rows.start, 0);
|
||||
let end = WrapPoint::new(rows.end, 0);
|
||||
|
||||
let mut cursor = self.transforms.cursor::<(WrapPoint, TabPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
cursor.seek(&start, Bias::Right);
|
||||
if let Some(transform) = cursor.item() {
|
||||
let start_in_transform = start.0 - cursor.start().0.0;
|
||||
|
@ -721,7 +727,9 @@ impl WrapSnapshot {
|
|||
}
|
||||
|
||||
pub fn row_infos(&self, start_row: u32) -> WrapRows<'_> {
|
||||
let mut transforms = self.transforms.cursor::<(WrapPoint, TabPoint)>(&());
|
||||
let mut transforms = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
transforms.seek(&WrapPoint::new(start_row, 0), Bias::Left);
|
||||
let mut input_row = transforms.start().1.row();
|
||||
if transforms.item().map_or(false, |t| t.is_isomorphic()) {
|
||||
|
@ -741,7 +749,9 @@ impl WrapSnapshot {
|
|||
}
|
||||
|
||||
pub fn to_tab_point(&self, point: WrapPoint) -> TabPoint {
|
||||
let mut cursor = self.transforms.cursor::<(WrapPoint, TabPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
let mut tab_point = cursor.start().1.0;
|
||||
if cursor.item().map_or(false, |t| t.is_isomorphic()) {
|
||||
|
@ -759,7 +769,9 @@ impl WrapSnapshot {
|
|||
}
|
||||
|
||||
pub fn tab_point_to_wrap_point(&self, point: TabPoint) -> WrapPoint {
|
||||
let mut cursor = self.transforms.cursor::<(TabPoint, WrapPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<TabPoint, WrapPoint>>(&());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
WrapPoint(cursor.start().1.0 + (point.0 - cursor.start().0.0))
|
||||
}
|
||||
|
@ -784,7 +796,9 @@ impl WrapSnapshot {
|
|||
|
||||
*point.column_mut() = 0;
|
||||
|
||||
let mut cursor = self.transforms.cursor::<(WrapPoint, TabPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
if cursor.item().is_none() {
|
||||
cursor.prev();
|
||||
|
@ -804,7 +818,9 @@ impl WrapSnapshot {
|
|||
pub fn next_row_boundary(&self, mut point: WrapPoint) -> Option<u32> {
|
||||
point.0 += Point::new(1, 0);
|
||||
|
||||
let mut cursor = self.transforms.cursor::<(WrapPoint, TabPoint)>(&());
|
||||
let mut cursor = self
|
||||
.transforms
|
||||
.cursor::<Dimensions<WrapPoint, TabPoint>>(&());
|
||||
cursor.seek(&point, Bias::Right);
|
||||
while let Some(transform) = cursor.item() {
|
||||
if transform.is_isomorphic() && cursor.start().1.column() == 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue