mirror of
https://github.com/zed-industries/zed.git
synced 2024-12-30 21:16:23 +00:00
Rename the new map
This commit is contained in:
parent
9287634548
commit
b5233b3ad5
5 changed files with 190 additions and 211 deletions
|
@ -1,6 +1,6 @@
|
|||
mod block_map;
|
||||
mod editor_addition_map;
|
||||
mod fold_map;
|
||||
mod inlay_map;
|
||||
mod suggestion_map;
|
||||
mod tab_map;
|
||||
mod wrap_map;
|
||||
|
@ -8,13 +8,13 @@ mod wrap_map;
|
|||
use crate::{Anchor, AnchorRangeExt, MultiBuffer, MultiBufferSnapshot, ToOffset, ToPoint};
|
||||
pub use block_map::{BlockMap, BlockPoint};
|
||||
use collections::{HashMap, HashSet};
|
||||
use editor_addition_map::EditorAdditionMap;
|
||||
use fold_map::{FoldMap, FoldOffset};
|
||||
use gpui::{
|
||||
color::Color,
|
||||
fonts::{FontId, HighlightStyle},
|
||||
Entity, ModelContext, ModelHandle,
|
||||
};
|
||||
use inlay_map::InlayMap;
|
||||
use language::{
|
||||
language_settings::language_settings, OffsetUtf16, Point, Subscription as BufferSubscription,
|
||||
};
|
||||
|
@ -30,7 +30,7 @@ pub use block_map::{
|
|||
BlockDisposition, BlockId, BlockProperties, BlockStyle, RenderBlock, TransformBlock,
|
||||
};
|
||||
|
||||
use self::editor_addition_map::InlayHintToRender;
|
||||
use self::inlay_map::InlayHintToRender;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum FoldStatus {
|
||||
|
@ -49,7 +49,7 @@ pub struct DisplayMap {
|
|||
buffer_subscription: BufferSubscription,
|
||||
fold_map: FoldMap,
|
||||
suggestion_map: SuggestionMap,
|
||||
editor_addition_map: EditorAdditionMap,
|
||||
inlay_map: InlayMap,
|
||||
tab_map: TabMap,
|
||||
wrap_map: ModelHandle<WrapMap>,
|
||||
block_map: BlockMap,
|
||||
|
@ -76,7 +76,7 @@ impl DisplayMap {
|
|||
let tab_size = Self::tab_size(&buffer, cx);
|
||||
let (fold_map, snapshot) = FoldMap::new(buffer.read(cx).snapshot(cx));
|
||||
let (suggestion_map, snapshot) = SuggestionMap::new(snapshot);
|
||||
let (editor_addition_map, snapshot) = EditorAdditionMap::new(snapshot);
|
||||
let (inlay_map, snapshot) = InlayMap::new(snapshot);
|
||||
let (tab_map, snapshot) = TabMap::new(snapshot, tab_size);
|
||||
let (wrap_map, snapshot) = WrapMap::new(snapshot, font_id, font_size, wrap_width, cx);
|
||||
let block_map = BlockMap::new(snapshot, buffer_header_height, excerpt_header_height);
|
||||
|
@ -86,7 +86,7 @@ impl DisplayMap {
|
|||
buffer_subscription,
|
||||
fold_map,
|
||||
suggestion_map,
|
||||
editor_addition_map,
|
||||
inlay_map,
|
||||
tab_map,
|
||||
wrap_map,
|
||||
block_map,
|
||||
|
@ -100,13 +100,13 @@ impl DisplayMap {
|
|||
let edits = self.buffer_subscription.consume().into_inner();
|
||||
let (fold_snapshot, edits) = self.fold_map.read(buffer_snapshot, edits);
|
||||
let (suggestion_snapshot, edits) = self.suggestion_map.sync(fold_snapshot.clone(), edits);
|
||||
let (editor_addition_snapshot, edits) = self
|
||||
.editor_addition_map
|
||||
let (inlay_snapshot, edits) = self
|
||||
.inlay_map
|
||||
.sync(suggestion_snapshot.clone(), edits);
|
||||
let tab_size = Self::tab_size(&self.buffer, cx);
|
||||
let (tab_snapshot, edits) =
|
||||
self.tab_map
|
||||
.sync(editor_addition_snapshot.clone(), edits, tab_size);
|
||||
.sync(inlay_snapshot.clone(), edits, tab_size);
|
||||
let (wrap_snapshot, edits) = self
|
||||
.wrap_map
|
||||
.update(cx, |map, cx| map.sync(tab_snapshot.clone(), edits, cx));
|
||||
|
@ -116,7 +116,7 @@ impl DisplayMap {
|
|||
buffer_snapshot: self.buffer.read(cx).snapshot(cx),
|
||||
fold_snapshot,
|
||||
suggestion_snapshot,
|
||||
editor_addition_snapshot,
|
||||
inlay_snapshot,
|
||||
tab_snapshot,
|
||||
wrap_snapshot,
|
||||
block_snapshot,
|
||||
|
@ -144,7 +144,7 @@ impl DisplayMap {
|
|||
let tab_size = Self::tab_size(&self.buffer, cx);
|
||||
let (mut fold_map, snapshot, edits) = self.fold_map.write(snapshot, edits);
|
||||
let (snapshot, edits) = self.suggestion_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.editor_addition_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
|
||||
let (snapshot, edits) = self
|
||||
.wrap_map
|
||||
|
@ -152,7 +152,7 @@ impl DisplayMap {
|
|||
self.block_map.read(snapshot, edits);
|
||||
let (snapshot, edits) = fold_map.fold(ranges);
|
||||
let (snapshot, edits) = self.suggestion_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.editor_addition_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
|
||||
let (snapshot, edits) = self
|
||||
.wrap_map
|
||||
|
@ -171,7 +171,7 @@ impl DisplayMap {
|
|||
let tab_size = Self::tab_size(&self.buffer, cx);
|
||||
let (mut fold_map, snapshot, edits) = self.fold_map.write(snapshot, edits);
|
||||
let (snapshot, edits) = self.suggestion_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.editor_addition_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
|
||||
let (snapshot, edits) = self
|
||||
.wrap_map
|
||||
|
@ -179,7 +179,7 @@ impl DisplayMap {
|
|||
self.block_map.read(snapshot, edits);
|
||||
let (snapshot, edits) = fold_map.unfold(ranges, inclusive);
|
||||
let (snapshot, edits) = self.suggestion_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.editor_addition_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
|
||||
let (snapshot, edits) = self
|
||||
.wrap_map
|
||||
|
@ -197,7 +197,7 @@ impl DisplayMap {
|
|||
let tab_size = Self::tab_size(&self.buffer, cx);
|
||||
let (snapshot, edits) = self.fold_map.read(snapshot, edits);
|
||||
let (snapshot, edits) = self.suggestion_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.editor_addition_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
|
||||
let (snapshot, edits) = self
|
||||
.wrap_map
|
||||
|
@ -216,7 +216,7 @@ impl DisplayMap {
|
|||
let tab_size = Self::tab_size(&self.buffer, cx);
|
||||
let (snapshot, edits) = self.fold_map.read(snapshot, edits);
|
||||
let (snapshot, edits) = self.suggestion_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.editor_addition_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
|
||||
let (snapshot, edits) = self
|
||||
.wrap_map
|
||||
|
@ -265,7 +265,7 @@ impl DisplayMap {
|
|||
let (snapshot, edits) = self.fold_map.read(snapshot, edits);
|
||||
let (snapshot, edits, old_suggestion) =
|
||||
self.suggestion_map.replace(new_suggestion, snapshot, edits);
|
||||
let (snapshot, edits) = self.editor_addition_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.inlay_map.sync(snapshot, edits);
|
||||
let (snapshot, edits) = self.tab_map.sync(snapshot, edits, tab_size);
|
||||
let (snapshot, edits) = self
|
||||
.wrap_map
|
||||
|
@ -302,7 +302,7 @@ impl DisplayMap {
|
|||
.map(|buffer_handle| buffer_handle.id())
|
||||
.collect::<HashSet<_>>());
|
||||
|
||||
self.editor_addition_map.set_inlay_hints(
|
||||
self.inlay_map.set_inlay_hints(
|
||||
new_hints
|
||||
.into_iter()
|
||||
.filter_map(|hint| {
|
||||
|
@ -312,9 +312,10 @@ impl DisplayMap {
|
|||
let buffer = dbg!(multi_buffer.buffer(dbg!(hint.buffer_id)))?.read(cx);
|
||||
let snapshot = buffer.snapshot();
|
||||
Some(InlayHintToRender {
|
||||
position: editor_addition_map::EditorAdditionPoint(
|
||||
text::ToPoint::to_point(&hint.position, &snapshot),
|
||||
),
|
||||
position: inlay_map::InlayPoint(text::ToPoint::to_point(
|
||||
&hint.position,
|
||||
&snapshot,
|
||||
)),
|
||||
text: hint.text().trim_end().into(),
|
||||
})
|
||||
})
|
||||
|
@ -340,7 +341,7 @@ pub struct DisplaySnapshot {
|
|||
pub buffer_snapshot: MultiBufferSnapshot,
|
||||
fold_snapshot: fold_map::FoldSnapshot,
|
||||
suggestion_snapshot: suggestion_map::SuggestionSnapshot,
|
||||
editor_addition_snapshot: editor_addition_map::EditorAdditionSnapshot,
|
||||
inlay_snapshot: inlay_map::InlaySnapshot,
|
||||
tab_snapshot: tab_map::TabSnapshot,
|
||||
wrap_snapshot: wrap_map::WrapSnapshot,
|
||||
block_snapshot: block_map::BlockSnapshot,
|
||||
|
@ -418,10 +419,10 @@ impl DisplaySnapshot {
|
|||
fn point_to_display_point(&self, point: Point, bias: Bias) -> DisplayPoint {
|
||||
let fold_point = self.fold_snapshot.to_fold_point(point, bias);
|
||||
let suggestion_point = self.suggestion_snapshot.to_suggestion_point(fold_point);
|
||||
let editor_addition_point = self
|
||||
.editor_addition_snapshot
|
||||
.to_editor_addition_point(suggestion_point);
|
||||
let tab_point = self.tab_snapshot.to_tab_point(editor_addition_point);
|
||||
let inlay_point = self
|
||||
.inlay_snapshot
|
||||
.to_inlay_point(suggestion_point);
|
||||
let tab_point = self.tab_snapshot.to_tab_point(inlay_point);
|
||||
let wrap_point = self.wrap_snapshot.tab_point_to_wrap_point(tab_point);
|
||||
let block_point = self.block_snapshot.to_block_point(wrap_point);
|
||||
DisplayPoint(block_point)
|
||||
|
@ -431,13 +432,13 @@ impl DisplaySnapshot {
|
|||
let block_point = point.0;
|
||||
let wrap_point = self.block_snapshot.to_wrap_point(block_point);
|
||||
let tab_point = self.wrap_snapshot.to_tab_point(wrap_point);
|
||||
let editor_addition_point = self
|
||||
let inlay_point = self
|
||||
.tab_snapshot
|
||||
.to_editor_addition_point(tab_point, bias)
|
||||
.to_inlay_point(tab_point, bias)
|
||||
.0;
|
||||
let suggestion_point = self
|
||||
.editor_addition_snapshot
|
||||
.to_suggestion_point(editor_addition_point, bias);
|
||||
.inlay_snapshot
|
||||
.to_suggestion_point(inlay_point, bias);
|
||||
let fold_point = self.suggestion_snapshot.to_fold_point(suggestion_point);
|
||||
fold_point.to_buffer_point(&self.fold_snapshot)
|
||||
}
|
||||
|
@ -851,10 +852,10 @@ impl DisplayPoint {
|
|||
pub fn to_offset(self, map: &DisplaySnapshot, bias: Bias) -> usize {
|
||||
let wrap_point = map.block_snapshot.to_wrap_point(self.0);
|
||||
let tab_point = map.wrap_snapshot.to_tab_point(wrap_point);
|
||||
let editor_addition_point = map.tab_snapshot.to_editor_addition_point(tab_point, bias).0;
|
||||
let inlay_point = map.tab_snapshot.to_inlay_point(tab_point, bias).0;
|
||||
let suggestion_point = map
|
||||
.editor_addition_snapshot
|
||||
.to_suggestion_point(editor_addition_point, bias);
|
||||
.inlay_snapshot
|
||||
.to_suggestion_point(inlay_point, bias);
|
||||
let fold_point = map.suggestion_snapshot.to_fold_point(suggestion_point);
|
||||
fold_point.to_buffer_offset(&map.fold_snapshot)
|
||||
}
|
||||
|
|
|
@ -989,7 +989,7 @@ fn offset_for_row(s: &str, target: u32) -> (u32, usize) {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::display_map::editor_addition_map::EditorAdditionMap;
|
||||
use crate::display_map::inlay_map::InlayMap;
|
||||
use crate::display_map::suggestion_map::SuggestionMap;
|
||||
use crate::display_map::{fold_map::FoldMap, tab_map::TabMap, wrap_map::WrapMap};
|
||||
use crate::multi_buffer::MultiBuffer;
|
||||
|
@ -1033,9 +1033,8 @@ mod tests {
|
|||
let subscription = buffer.update(cx, |buffer, _| buffer.subscribe());
|
||||
let (fold_map, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
|
||||
let (suggestion_map, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
|
||||
let (editor_addition_map, editor_addition_snapshot) =
|
||||
EditorAdditionMap::new(suggestion_snapshot);
|
||||
let (tab_map, tab_snapshot) = TabMap::new(editor_addition_snapshot, 1.try_into().unwrap());
|
||||
let (inlay_map, inlay_snapshot) = InlayMap::new(suggestion_snapshot);
|
||||
let (tab_map, tab_snapshot) = TabMap::new(inlay_snapshot, 1.try_into().unwrap());
|
||||
let (wrap_map, wraps_snapshot) = WrapMap::new(tab_snapshot, font_id, 14.0, None, cx);
|
||||
let mut block_map = BlockMap::new(wraps_snapshot.clone(), 1, 1);
|
||||
|
||||
|
@ -1182,13 +1181,10 @@ mod tests {
|
|||
fold_map.read(buffer_snapshot, subscription.consume().into_inner());
|
||||
let (suggestion_snapshot, suggestion_edits) =
|
||||
suggestion_map.sync(fold_snapshot, fold_edits);
|
||||
let (editor_addition_snapshot, editor_addition_edits) =
|
||||
editor_addition_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (tab_snapshot, tab_edits) = tab_map.sync(
|
||||
editor_addition_snapshot,
|
||||
editor_addition_edits,
|
||||
4.try_into().unwrap(),
|
||||
);
|
||||
let (inlay_snapshot, inlay_edits) =
|
||||
inlay_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (tab_snapshot, tab_edits) =
|
||||
tab_map.sync(inlay_snapshot, inlay_edits, 4.try_into().unwrap());
|
||||
let (wraps_snapshot, wrap_edits) = wrap_map.update(cx, |wrap_map, cx| {
|
||||
wrap_map.sync(tab_snapshot, tab_edits, cx)
|
||||
});
|
||||
|
@ -1215,8 +1211,8 @@ mod tests {
|
|||
let buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||
let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
|
||||
let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
|
||||
let (_, editor_addition_snapshot) = EditorAdditionMap::new(suggestion_snapshot);
|
||||
let (_, tab_snapshot) = TabMap::new(editor_addition_snapshot, 4.try_into().unwrap());
|
||||
let (_, inlay_snapshot) = InlayMap::new(suggestion_snapshot);
|
||||
let (_, tab_snapshot) = TabMap::new(inlay_snapshot, 4.try_into().unwrap());
|
||||
let (_, wraps_snapshot) = WrapMap::new(tab_snapshot, font_id, 14.0, Some(60.), cx);
|
||||
let mut block_map = BlockMap::new(wraps_snapshot.clone(), 1, 1);
|
||||
|
||||
|
@ -1288,9 +1284,8 @@ mod tests {
|
|||
let mut buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||
let (fold_map, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
|
||||
let (suggestion_map, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
|
||||
let (editor_addition_map, editor_addition_snapshot) =
|
||||
EditorAdditionMap::new(suggestion_snapshot);
|
||||
let (tab_map, tab_snapshot) = TabMap::new(editor_addition_snapshot, 4.try_into().unwrap());
|
||||
let (inlay_map, inlay_snapshot) = InlayMap::new(suggestion_snapshot);
|
||||
let (tab_map, tab_snapshot) = TabMap::new(inlay_snapshot, 4.try_into().unwrap());
|
||||
let (wrap_map, wraps_snapshot) =
|
||||
WrapMap::new(tab_snapshot, font_id, font_size, wrap_width, cx);
|
||||
let mut block_map = BlockMap::new(
|
||||
|
@ -1347,10 +1342,10 @@ mod tests {
|
|||
fold_map.read(buffer_snapshot.clone(), vec![]);
|
||||
let (suggestion_snapshot, suggestion_edits) =
|
||||
suggestion_map.sync(fold_snapshot, fold_edits);
|
||||
let (editor_addition_snapshot, editor_addition_edits) =
|
||||
editor_addition_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (inlay_snapshot, inlay_edits) =
|
||||
inlay_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (tab_snapshot, tab_edits) =
|
||||
tab_map.sync(editor_addition_snapshot, editor_addition_edits, tab_size);
|
||||
tab_map.sync(inlay_snapshot, inlay_edits, tab_size);
|
||||
let (wraps_snapshot, wrap_edits) = wrap_map.update(cx, |wrap_map, cx| {
|
||||
wrap_map.sync(tab_snapshot, tab_edits, cx)
|
||||
});
|
||||
|
@ -1374,10 +1369,10 @@ mod tests {
|
|||
fold_map.read(buffer_snapshot.clone(), vec![]);
|
||||
let (suggestion_snapshot, suggestion_edits) =
|
||||
suggestion_map.sync(fold_snapshot, fold_edits);
|
||||
let (editor_addition_snapshot, editor_addition_edits) =
|
||||
editor_addition_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (inlay_snapshot, inlay_edits) =
|
||||
inlay_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (tab_snapshot, tab_edits) =
|
||||
tab_map.sync(editor_addition_snapshot, editor_addition_edits, tab_size);
|
||||
tab_map.sync(inlay_snapshot, inlay_edits, tab_size);
|
||||
let (wraps_snapshot, wrap_edits) = wrap_map.update(cx, |wrap_map, cx| {
|
||||
wrap_map.sync(tab_snapshot, tab_edits, cx)
|
||||
});
|
||||
|
@ -1399,10 +1394,10 @@ mod tests {
|
|||
let (fold_snapshot, fold_edits) = fold_map.read(buffer_snapshot.clone(), buffer_edits);
|
||||
let (suggestion_snapshot, suggestion_edits) =
|
||||
suggestion_map.sync(fold_snapshot, fold_edits);
|
||||
let (editor_addition_snapshot, editor_addition_edits) =
|
||||
editor_addition_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (inlay_snapshot, inlay_edits) =
|
||||
inlay_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (tab_snapshot, tab_edits) =
|
||||
tab_map.sync(editor_addition_snapshot, editor_addition_edits, tab_size);
|
||||
tab_map.sync(inlay_snapshot, inlay_edits, tab_size);
|
||||
let (wraps_snapshot, wrap_edits) = wrap_map.update(cx, |wrap_map, cx| {
|
||||
wrap_map.sync(tab_snapshot, tab_edits, cx)
|
||||
});
|
||||
|
|
|
@ -26,14 +26,14 @@ use sum_tree::{Bias, SumTree};
|
|||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct InlayHintId(usize);
|
||||
|
||||
pub struct EditorAdditionMap {
|
||||
snapshot: Mutex<EditorAdditionSnapshot>,
|
||||
pub struct InlayMap {
|
||||
snapshot: Mutex<InlaySnapshot>,
|
||||
next_hint_id: AtomicUsize,
|
||||
hints: HashMap<InlayHintId, InlayHintToRender>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct EditorAdditionSnapshot {
|
||||
pub struct InlaySnapshot {
|
||||
// TODO kb merge these two together
|
||||
pub suggestion_snapshot: SuggestionSnapshot,
|
||||
transforms: SumTree<Transform>,
|
||||
|
@ -54,12 +54,12 @@ impl sum_tree::Item for Transform {
|
|||
}
|
||||
}
|
||||
|
||||
pub type EditorAdditionEdit = Edit<EditorAdditionOffset>;
|
||||
pub type InlayEdit = Edit<InlayOffset>;
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
|
||||
pub struct EditorAdditionOffset(pub usize);
|
||||
pub struct InlayOffset(pub usize);
|
||||
|
||||
impl Add for EditorAdditionOffset {
|
||||
impl Add for InlayOffset {
|
||||
type Output = Self;
|
||||
|
||||
fn add(self, rhs: Self) -> Self::Output {
|
||||
|
@ -67,7 +67,7 @@ impl Add for EditorAdditionOffset {
|
|||
}
|
||||
}
|
||||
|
||||
impl Sub for EditorAdditionOffset {
|
||||
impl Sub for InlayOffset {
|
||||
type Output = Self;
|
||||
|
||||
fn sub(self, rhs: Self) -> Self::Output {
|
||||
|
@ -75,31 +75,31 @@ impl Sub for EditorAdditionOffset {
|
|||
}
|
||||
}
|
||||
|
||||
impl AddAssign for EditorAdditionOffset {
|
||||
impl AddAssign for InlayOffset {
|
||||
fn add_assign(&mut self, rhs: Self) {
|
||||
self.0 += rhs.0;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Default, Eq, Ord, PartialOrd, PartialEq)]
|
||||
pub struct EditorAdditionPoint(pub Point);
|
||||
pub struct InlayPoint(pub Point);
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct EditorAdditionBufferRows<'a> {
|
||||
pub struct InlayBufferRows<'a> {
|
||||
suggestion_rows: SuggestionBufferRows<'a>,
|
||||
}
|
||||
|
||||
pub struct EditorAdditionChunks<'a> {
|
||||
pub struct InlayChunks<'a> {
|
||||
suggestion_chunks: SuggestionChunks<'a>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct InlayHintToRender {
|
||||
pub(super) position: EditorAdditionPoint,
|
||||
pub(super) position: InlayPoint,
|
||||
pub(super) text: Rope,
|
||||
}
|
||||
|
||||
impl<'a> Iterator for EditorAdditionChunks<'a> {
|
||||
impl<'a> Iterator for InlayChunks<'a> {
|
||||
type Item = Chunk<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -107,7 +107,7 @@ impl<'a> Iterator for EditorAdditionChunks<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> Iterator for EditorAdditionBufferRows<'a> {
|
||||
impl<'a> Iterator for InlayBufferRows<'a> {
|
||||
type Item = Option<u32>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
|
@ -115,7 +115,7 @@ impl<'a> Iterator for EditorAdditionBufferRows<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl EditorAdditionPoint {
|
||||
impl InlayPoint {
|
||||
pub fn new(row: u32, column: u32) -> Self {
|
||||
Self(Point::new(row, column))
|
||||
}
|
||||
|
@ -129,9 +129,9 @@ impl EditorAdditionPoint {
|
|||
}
|
||||
}
|
||||
|
||||
impl EditorAdditionMap {
|
||||
pub fn new(suggestion_snapshot: SuggestionSnapshot) -> (Self, EditorAdditionSnapshot) {
|
||||
let snapshot = EditorAdditionSnapshot {
|
||||
impl InlayMap {
|
||||
pub fn new(suggestion_snapshot: SuggestionSnapshot) -> (Self, InlaySnapshot) {
|
||||
let snapshot = InlaySnapshot {
|
||||
suggestion_snapshot: suggestion_snapshot.clone(),
|
||||
version: 0,
|
||||
transforms: SumTree::new(),
|
||||
|
@ -151,29 +151,29 @@ impl EditorAdditionMap {
|
|||
&self,
|
||||
suggestion_snapshot: SuggestionSnapshot,
|
||||
suggestion_edits: Vec<SuggestionEdit>,
|
||||
) -> (EditorAdditionSnapshot, Vec<EditorAdditionEdit>) {
|
||||
) -> (InlaySnapshot, Vec<InlayEdit>) {
|
||||
let mut snapshot = self.snapshot.lock();
|
||||
|
||||
if snapshot.suggestion_snapshot.version != suggestion_snapshot.version {
|
||||
snapshot.version += 1;
|
||||
}
|
||||
|
||||
let mut editor_addition_edits = Vec::new();
|
||||
let mut inlay_edits = Vec::new();
|
||||
|
||||
dbg!(&suggestion_edits);
|
||||
for suggestion_edit in suggestion_edits {
|
||||
let old = suggestion_edit.old;
|
||||
let new = suggestion_edit.new;
|
||||
// TODO kb copied from suggestion_map
|
||||
editor_addition_edits.push(EditorAdditionEdit {
|
||||
old: EditorAdditionOffset(old.start.0)..EditorAdditionOffset(old.end.0),
|
||||
new: EditorAdditionOffset(old.start.0)..EditorAdditionOffset(new.end.0),
|
||||
inlay_edits.push(InlayEdit {
|
||||
old: InlayOffset(old.start.0)..InlayOffset(old.end.0),
|
||||
new: InlayOffset(old.start.0)..InlayOffset(new.end.0),
|
||||
})
|
||||
}
|
||||
|
||||
snapshot.suggestion_snapshot = suggestion_snapshot;
|
||||
|
||||
(snapshot.clone(), editor_addition_edits)
|
||||
(snapshot.clone(), inlay_edits)
|
||||
}
|
||||
|
||||
// TODO kb replace set_inlay_hints with this
|
||||
|
@ -204,57 +204,57 @@ impl EditorAdditionMap {
|
|||
}
|
||||
}
|
||||
|
||||
impl EditorAdditionSnapshot {
|
||||
impl InlaySnapshot {
|
||||
pub fn buffer_snapshot(&self) -> &MultiBufferSnapshot {
|
||||
// TODO kb copied from suggestion_map
|
||||
self.suggestion_snapshot.buffer_snapshot()
|
||||
}
|
||||
|
||||
pub fn to_point(&self, offset: EditorAdditionOffset) -> EditorAdditionPoint {
|
||||
pub fn to_point(&self, offset: InlayOffset) -> InlayPoint {
|
||||
// TODO kb copied from suggestion_map
|
||||
self.to_editor_addition_point(
|
||||
self.to_inlay_point(
|
||||
self.suggestion_snapshot
|
||||
.to_point(super::suggestion_map::SuggestionOffset(offset.0)),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn max_point(&self) -> EditorAdditionPoint {
|
||||
pub fn max_point(&self) -> InlayPoint {
|
||||
// TODO kb copied from suggestion_map
|
||||
self.to_editor_addition_point(self.suggestion_snapshot.max_point())
|
||||
self.to_inlay_point(self.suggestion_snapshot.max_point())
|
||||
}
|
||||
|
||||
pub fn to_offset(&self, point: EditorAdditionPoint) -> EditorAdditionOffset {
|
||||
pub fn to_offset(&self, point: InlayPoint) -> InlayOffset {
|
||||
// TODO kb copied from suggestion_map
|
||||
EditorAdditionOffset(
|
||||
InlayOffset(
|
||||
self.suggestion_snapshot
|
||||
.to_offset(self.to_suggestion_point(point, Bias::Left))
|
||||
.0,
|
||||
)
|
||||
}
|
||||
|
||||
pub fn chars_at(&self, start: EditorAdditionPoint) -> impl '_ + Iterator<Item = char> {
|
||||
pub fn chars_at(&self, start: InlayPoint) -> impl '_ + Iterator<Item = char> {
|
||||
self.suggestion_snapshot
|
||||
.chars_at(self.to_suggestion_point(start, Bias::Left))
|
||||
}
|
||||
|
||||
// TODO kb what to do with bias?
|
||||
pub fn to_suggestion_point(&self, point: EditorAdditionPoint, _: Bias) -> SuggestionPoint {
|
||||
pub fn to_suggestion_point(&self, point: InlayPoint, _: Bias) -> SuggestionPoint {
|
||||
SuggestionPoint(point.0)
|
||||
}
|
||||
|
||||
pub fn to_editor_addition_point(&self, point: SuggestionPoint) -> EditorAdditionPoint {
|
||||
EditorAdditionPoint(point.0)
|
||||
pub fn to_inlay_point(&self, point: SuggestionPoint) -> InlayPoint {
|
||||
InlayPoint(point.0)
|
||||
}
|
||||
|
||||
pub fn clip_point(&self, point: EditorAdditionPoint, bias: Bias) -> EditorAdditionPoint {
|
||||
pub fn clip_point(&self, point: InlayPoint, bias: Bias) -> InlayPoint {
|
||||
// TODO kb copied from suggestion_map
|
||||
self.to_editor_addition_point(
|
||||
self.to_inlay_point(
|
||||
self.suggestion_snapshot
|
||||
.clip_point(self.to_suggestion_point(point, bias), bias),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn text_summary_for_range(&self, range: Range<EditorAdditionPoint>) -> TextSummary {
|
||||
pub fn text_summary_for_range(&self, range: Range<InlayPoint>) -> TextSummary {
|
||||
// TODO kb copied from suggestion_map
|
||||
self.suggestion_snapshot.text_summary_for_range(
|
||||
self.to_suggestion_point(range.start, Bias::Left)
|
||||
|
@ -262,8 +262,8 @@ impl EditorAdditionSnapshot {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn buffer_rows<'a>(&'a self, row: u32) -> EditorAdditionBufferRows<'a> {
|
||||
EditorAdditionBufferRows {
|
||||
pub fn buffer_rows<'a>(&'a self, row: u32) -> InlayBufferRows<'a> {
|
||||
InlayBufferRows {
|
||||
suggestion_rows: self.suggestion_snapshot.buffer_rows(row),
|
||||
}
|
||||
}
|
||||
|
@ -275,13 +275,13 @@ impl EditorAdditionSnapshot {
|
|||
|
||||
pub fn chunks<'a>(
|
||||
&'a self,
|
||||
range: Range<EditorAdditionOffset>,
|
||||
range: Range<InlayOffset>,
|
||||
language_aware: bool,
|
||||
text_highlights: Option<&'a TextHighlights>,
|
||||
suggestion_highlight: Option<HighlightStyle>,
|
||||
) -> EditorAdditionChunks<'a> {
|
||||
) -> InlayChunks<'a> {
|
||||
// TODO kb copied from suggestion_map
|
||||
EditorAdditionChunks {
|
||||
InlayChunks {
|
||||
suggestion_chunks: self.suggestion_snapshot.chunks(
|
||||
SuggestionOffset(range.start.0)..SuggestionOffset(range.end.0),
|
||||
language_aware,
|
|
@ -1,7 +1,5 @@
|
|||
use super::{
|
||||
editor_addition_map::{
|
||||
self, EditorAdditionChunks, EditorAdditionEdit, EditorAdditionPoint, EditorAdditionSnapshot,
|
||||
},
|
||||
inlay_map::{self, InlayChunks, InlayEdit, InlayPoint, InlaySnapshot},
|
||||
TextHighlights,
|
||||
};
|
||||
use crate::MultiBufferSnapshot;
|
||||
|
@ -16,9 +14,9 @@ const MAX_EXPANSION_COLUMN: u32 = 256;
|
|||
pub struct TabMap(Mutex<TabSnapshot>);
|
||||
|
||||
impl TabMap {
|
||||
pub fn new(input: EditorAdditionSnapshot, tab_size: NonZeroU32) -> (Self, TabSnapshot) {
|
||||
pub fn new(input: InlaySnapshot, tab_size: NonZeroU32) -> (Self, TabSnapshot) {
|
||||
let snapshot = TabSnapshot {
|
||||
editor_addition_snapshot: input,
|
||||
inlay_snapshot: input,
|
||||
tab_size,
|
||||
max_expansion_column: MAX_EXPANSION_COLUMN,
|
||||
version: 0,
|
||||
|
@ -34,20 +32,20 @@ impl TabMap {
|
|||
|
||||
pub fn sync(
|
||||
&self,
|
||||
editor_addition_snapshot: EditorAdditionSnapshot,
|
||||
mut suggestion_edits: Vec<EditorAdditionEdit>,
|
||||
inlay_snapshot: InlaySnapshot,
|
||||
mut suggestion_edits: Vec<InlayEdit>,
|
||||
tab_size: NonZeroU32,
|
||||
) -> (TabSnapshot, Vec<TabEdit>) {
|
||||
let mut old_snapshot = self.0.lock();
|
||||
let mut new_snapshot = TabSnapshot {
|
||||
editor_addition_snapshot,
|
||||
inlay_snapshot,
|
||||
tab_size,
|
||||
max_expansion_column: old_snapshot.max_expansion_column,
|
||||
version: old_snapshot.version,
|
||||
};
|
||||
|
||||
if old_snapshot.editor_addition_snapshot.version
|
||||
!= new_snapshot.editor_addition_snapshot.version
|
||||
if old_snapshot.inlay_snapshot.version
|
||||
!= new_snapshot.inlay_snapshot.version
|
||||
{
|
||||
new_snapshot.version += 1;
|
||||
}
|
||||
|
@ -60,21 +58,21 @@ impl TabMap {
|
|||
// boundary.
|
||||
for suggestion_edit in &mut suggestion_edits {
|
||||
let old_end = old_snapshot
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.to_point(suggestion_edit.old.end);
|
||||
let old_end_row_successor_offset =
|
||||
old_snapshot.editor_addition_snapshot.to_offset(cmp::min(
|
||||
EditorAdditionPoint::new(old_end.row() + 1, 0),
|
||||
old_snapshot.editor_addition_snapshot.max_point(),
|
||||
old_snapshot.inlay_snapshot.to_offset(cmp::min(
|
||||
InlayPoint::new(old_end.row() + 1, 0),
|
||||
old_snapshot.inlay_snapshot.max_point(),
|
||||
));
|
||||
let new_end = new_snapshot
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.to_point(suggestion_edit.new.end);
|
||||
|
||||
let mut offset_from_edit = 0;
|
||||
let mut first_tab_offset = None;
|
||||
let mut last_tab_with_changed_expansion_offset = None;
|
||||
'outer: for chunk in old_snapshot.editor_addition_snapshot.chunks(
|
||||
'outer: for chunk in old_snapshot.inlay_snapshot.chunks(
|
||||
suggestion_edit.old.end..old_end_row_successor_offset,
|
||||
false,
|
||||
None,
|
||||
|
@ -128,16 +126,16 @@ impl TabMap {
|
|||
|
||||
for suggestion_edit in suggestion_edits {
|
||||
let old_start = old_snapshot
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.to_point(suggestion_edit.old.start);
|
||||
let old_end = old_snapshot
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.to_point(suggestion_edit.old.end);
|
||||
let new_start = new_snapshot
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.to_point(suggestion_edit.new.start);
|
||||
let new_end = new_snapshot
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.to_point(suggestion_edit.new.end);
|
||||
tab_edits.push(TabEdit {
|
||||
old: old_snapshot.to_tab_point(old_start)..old_snapshot.to_tab_point(old_end),
|
||||
|
@ -159,7 +157,7 @@ impl TabMap {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct TabSnapshot {
|
||||
pub editor_addition_snapshot: EditorAdditionSnapshot,
|
||||
pub inlay_snapshot: InlaySnapshot,
|
||||
pub tab_size: NonZeroU32,
|
||||
pub max_expansion_column: u32,
|
||||
pub version: usize,
|
||||
|
@ -167,15 +165,15 @@ pub struct TabSnapshot {
|
|||
|
||||
impl TabSnapshot {
|
||||
pub fn buffer_snapshot(&self) -> &MultiBufferSnapshot {
|
||||
self.editor_addition_snapshot.buffer_snapshot()
|
||||
self.inlay_snapshot.buffer_snapshot()
|
||||
}
|
||||
|
||||
pub fn line_len(&self, row: u32) -> u32 {
|
||||
let max_point = self.max_point();
|
||||
if row < max_point.row() {
|
||||
self.to_tab_point(EditorAdditionPoint::new(
|
||||
self.to_tab_point(InlayPoint::new(
|
||||
row,
|
||||
self.editor_addition_snapshot.line_len(row),
|
||||
self.inlay_snapshot.line_len(row),
|
||||
))
|
||||
.0
|
||||
.column
|
||||
|
@ -189,10 +187,10 @@ impl TabSnapshot {
|
|||
}
|
||||
|
||||
pub fn text_summary_for_range(&self, range: Range<TabPoint>) -> TextSummary {
|
||||
let input_start = self.to_editor_addition_point(range.start, Bias::Left).0;
|
||||
let input_end = self.to_editor_addition_point(range.end, Bias::Right).0;
|
||||
let input_start = self.to_inlay_point(range.start, Bias::Left).0;
|
||||
let input_end = self.to_inlay_point(range.end, Bias::Right).0;
|
||||
let input_summary = self
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.text_summary_for_range(input_start..input_end);
|
||||
|
||||
let mut first_line_chars = 0;
|
||||
|
@ -245,12 +243,12 @@ impl TabSnapshot {
|
|||
suggestion_highlight: Option<HighlightStyle>,
|
||||
) -> TabChunks<'a> {
|
||||
let (input_start, expanded_char_column, to_next_stop) =
|
||||
self.to_editor_addition_point(range.start, Bias::Left);
|
||||
self.to_inlay_point(range.start, Bias::Left);
|
||||
let input_column = input_start.column();
|
||||
let input_start = self.editor_addition_snapshot.to_offset(input_start);
|
||||
let input_start = self.inlay_snapshot.to_offset(input_start);
|
||||
let input_end = self
|
||||
.editor_addition_snapshot
|
||||
.to_offset(self.to_editor_addition_point(range.end, Bias::Right).0);
|
||||
.inlay_snapshot
|
||||
.to_offset(self.to_inlay_point(range.end, Bias::Right).0);
|
||||
let to_next_stop = if range.start.0 + Point::new(0, to_next_stop) > range.end.0 {
|
||||
range.end.column() - range.start.column()
|
||||
} else {
|
||||
|
@ -258,7 +256,7 @@ impl TabSnapshot {
|
|||
};
|
||||
|
||||
TabChunks {
|
||||
editor_addition_chunks: self.editor_addition_snapshot.chunks(
|
||||
inlay_chunks: self.inlay_snapshot.chunks(
|
||||
input_start..input_end,
|
||||
language_aware,
|
||||
text_highlights,
|
||||
|
@ -279,8 +277,8 @@ impl TabSnapshot {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn buffer_rows(&self, row: u32) -> editor_addition_map::EditorAdditionBufferRows<'_> {
|
||||
self.editor_addition_snapshot.buffer_rows(row)
|
||||
pub fn buffer_rows(&self, row: u32) -> inlay_map::InlayBufferRows<'_> {
|
||||
self.inlay_snapshot.buffer_rows(row)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -291,37 +289,33 @@ impl TabSnapshot {
|
|||
}
|
||||
|
||||
pub fn max_point(&self) -> TabPoint {
|
||||
self.to_tab_point(self.editor_addition_snapshot.max_point())
|
||||
self.to_tab_point(self.inlay_snapshot.max_point())
|
||||
}
|
||||
|
||||
pub fn clip_point(&self, point: TabPoint, bias: Bias) -> TabPoint {
|
||||
self.to_tab_point(
|
||||
self.editor_addition_snapshot
|
||||
.clip_point(self.to_editor_addition_point(point, bias).0, bias),
|
||||
self.inlay_snapshot
|
||||
.clip_point(self.to_inlay_point(point, bias).0, bias),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn to_tab_point(&self, input: EditorAdditionPoint) -> TabPoint {
|
||||
pub fn to_tab_point(&self, input: InlayPoint) -> TabPoint {
|
||||
let chars = self
|
||||
.editor_addition_snapshot
|
||||
.chars_at(EditorAdditionPoint::new(input.row(), 0));
|
||||
.inlay_snapshot
|
||||
.chars_at(InlayPoint::new(input.row(), 0));
|
||||
let expanded = self.expand_tabs(chars, input.column());
|
||||
TabPoint::new(input.row(), expanded)
|
||||
}
|
||||
|
||||
pub fn to_editor_addition_point(
|
||||
&self,
|
||||
output: TabPoint,
|
||||
bias: Bias,
|
||||
) -> (EditorAdditionPoint, u32, u32) {
|
||||
pub fn to_inlay_point(&self, output: TabPoint, bias: Bias) -> (InlayPoint, u32, u32) {
|
||||
let chars = self
|
||||
.editor_addition_snapshot
|
||||
.chars_at(EditorAdditionPoint::new(output.row(), 0));
|
||||
.inlay_snapshot
|
||||
.chars_at(InlayPoint::new(output.row(), 0));
|
||||
let expanded = output.column();
|
||||
let (collapsed, expanded_char_column, to_next_stop) =
|
||||
self.collapse_tabs(chars, expanded, bias);
|
||||
(
|
||||
EditorAdditionPoint::new(output.row(), collapsed as u32),
|
||||
InlayPoint::new(output.row(), collapsed as u32),
|
||||
expanded_char_column,
|
||||
to_next_stop,
|
||||
)
|
||||
|
@ -329,32 +323,32 @@ impl TabSnapshot {
|
|||
|
||||
pub fn make_tab_point(&self, point: Point, bias: Bias) -> TabPoint {
|
||||
let fold_point = self
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.suggestion_snapshot
|
||||
.fold_snapshot
|
||||
.to_fold_point(point, bias);
|
||||
let suggestion_point = self
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.suggestion_snapshot
|
||||
.to_suggestion_point(fold_point);
|
||||
let editor_addition_point = self
|
||||
.editor_addition_snapshot
|
||||
.to_editor_addition_point(suggestion_point);
|
||||
self.to_tab_point(editor_addition_point)
|
||||
let inlay_point = self
|
||||
.inlay_snapshot
|
||||
.to_inlay_point(suggestion_point);
|
||||
self.to_tab_point(inlay_point)
|
||||
}
|
||||
|
||||
pub fn to_point(&self, point: TabPoint, bias: Bias) -> Point {
|
||||
let editor_addition_point = self.to_editor_addition_point(point, bias).0;
|
||||
let inlay_point = self.to_inlay_point(point, bias).0;
|
||||
let suggestion_point = self
|
||||
.editor_addition_snapshot
|
||||
.to_suggestion_point(editor_addition_point, bias);
|
||||
.inlay_snapshot
|
||||
.to_suggestion_point(inlay_point, bias);
|
||||
let fold_point = self
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.suggestion_snapshot
|
||||
.to_fold_point(suggestion_point);
|
||||
fold_point.to_buffer_point(
|
||||
&self
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.suggestion_snapshot
|
||||
.fold_snapshot,
|
||||
)
|
||||
|
@ -516,7 +510,7 @@ impl<'a> std::ops::AddAssign<&'a Self> for TextSummary {
|
|||
const SPACES: &str = " ";
|
||||
|
||||
pub struct TabChunks<'a> {
|
||||
editor_addition_chunks: EditorAdditionChunks<'a>,
|
||||
inlay_chunks: InlayChunks<'a>,
|
||||
chunk: Chunk<'a>,
|
||||
column: u32,
|
||||
max_expansion_column: u32,
|
||||
|
@ -532,7 +526,7 @@ impl<'a> Iterator for TabChunks<'a> {
|
|||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.chunk.text.is_empty() {
|
||||
if let Some(chunk) = self.editor_addition_chunks.next() {
|
||||
if let Some(chunk) = self.inlay_chunks.next() {
|
||||
self.chunk = chunk;
|
||||
if self.inside_leading_tab {
|
||||
self.chunk.text = &self.chunk.text[1..];
|
||||
|
@ -600,10 +594,7 @@ impl<'a> Iterator for TabChunks<'a> {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
display_map::{
|
||||
editor_addition_map::EditorAdditionMap, fold_map::FoldMap,
|
||||
suggestion_map::SuggestionMap,
|
||||
},
|
||||
display_map::{fold_map::FoldMap, inlay_map::InlayMap, suggestion_map::SuggestionMap},
|
||||
MultiBuffer,
|
||||
};
|
||||
use rand::{prelude::StdRng, Rng};
|
||||
|
@ -614,8 +605,8 @@ mod tests {
|
|||
let buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||
let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
|
||||
let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
|
||||
let (_, editor_addition_snapshot) = EditorAdditionMap::new(suggestion_snapshot);
|
||||
let (_, tab_snapshot) = TabMap::new(editor_addition_snapshot, 4.try_into().unwrap());
|
||||
let (_, inlay_snapshot) = InlayMap::new(suggestion_snapshot);
|
||||
let (_, tab_snapshot) = TabMap::new(inlay_snapshot, 4.try_into().unwrap());
|
||||
|
||||
assert_eq!(tab_snapshot.expand_tabs("\t".chars(), 0), 0);
|
||||
assert_eq!(tab_snapshot.expand_tabs("\t".chars(), 1), 4);
|
||||
|
@ -632,8 +623,8 @@ mod tests {
|
|||
let buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||
let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
|
||||
let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
|
||||
let (_, editor_addition_snapshot) = EditorAdditionMap::new(suggestion_snapshot);
|
||||
let (_, mut tab_snapshot) = TabMap::new(editor_addition_snapshot, 4.try_into().unwrap());
|
||||
let (_, inlay_snapshot) = InlayMap::new(suggestion_snapshot);
|
||||
let (_, mut tab_snapshot) = TabMap::new(inlay_snapshot, 4.try_into().unwrap());
|
||||
|
||||
tab_snapshot.max_expansion_column = max_expansion_column;
|
||||
assert_eq!(tab_snapshot.text(), output);
|
||||
|
@ -657,15 +648,15 @@ mod tests {
|
|||
let input_point = Point::new(0, ix as u32);
|
||||
let output_point = Point::new(0, output.find(c).unwrap() as u32);
|
||||
assert_eq!(
|
||||
tab_snapshot.to_tab_point(EditorAdditionPoint(input_point)),
|
||||
tab_snapshot.to_tab_point(InlayPoint(input_point)),
|
||||
TabPoint(output_point),
|
||||
"to_tab_point({input_point:?})"
|
||||
);
|
||||
assert_eq!(
|
||||
tab_snapshot
|
||||
.to_editor_addition_point(TabPoint(output_point), Bias::Left)
|
||||
.to_inlay_point(TabPoint(output_point), Bias::Left)
|
||||
.0,
|
||||
EditorAdditionPoint(input_point),
|
||||
InlayPoint(input_point),
|
||||
"to_suggestion_point({output_point:?})"
|
||||
);
|
||||
}
|
||||
|
@ -681,8 +672,8 @@ mod tests {
|
|||
let buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||
let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
|
||||
let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
|
||||
let (_, editor_addition_snapshot) = EditorAdditionMap::new(suggestion_snapshot);
|
||||
let (_, mut tab_snapshot) = TabMap::new(editor_addition_snapshot, 4.try_into().unwrap());
|
||||
let (_, inlay_snapshot) = InlayMap::new(suggestion_snapshot);
|
||||
let (_, mut tab_snapshot) = TabMap::new(inlay_snapshot, 4.try_into().unwrap());
|
||||
|
||||
tab_snapshot.max_expansion_column = max_expansion_column;
|
||||
assert_eq!(tab_snapshot.text(), input);
|
||||
|
@ -696,8 +687,8 @@ mod tests {
|
|||
let buffer_snapshot = buffer.read(cx).snapshot(cx);
|
||||
let (_, fold_snapshot) = FoldMap::new(buffer_snapshot.clone());
|
||||
let (_, suggestion_snapshot) = SuggestionMap::new(fold_snapshot);
|
||||
let (_, editor_addition_snapshot) = EditorAdditionMap::new(suggestion_snapshot);
|
||||
let (_, tab_snapshot) = TabMap::new(editor_addition_snapshot, 4.try_into().unwrap());
|
||||
let (_, inlay_snapshot) = InlayMap::new(suggestion_snapshot);
|
||||
let (_, tab_snapshot) = TabMap::new(inlay_snapshot, 4.try_into().unwrap());
|
||||
|
||||
assert_eq!(
|
||||
chunks(&tab_snapshot, TabPoint::zero()),
|
||||
|
@ -761,13 +752,10 @@ mod tests {
|
|||
let (suggestion_map, _) = SuggestionMap::new(fold_snapshot);
|
||||
let (suggestion_snapshot, _) = suggestion_map.randomly_mutate(&mut rng);
|
||||
log::info!("SuggestionMap text: {:?}", suggestion_snapshot.text());
|
||||
let (_, editor_addition_snapshot) = EditorAdditionMap::new(suggestion_snapshot.clone());
|
||||
log::info!(
|
||||
"EditorAdditionMap text: {:?}",
|
||||
editor_addition_snapshot.text()
|
||||
);
|
||||
let (_, inlay_snapshot) = InlayMap::new(suggestion_snapshot.clone());
|
||||
log::info!("InlayMap text: {:?}", inlay_snapshot.text());
|
||||
|
||||
let (tab_map, _) = TabMap::new(editor_addition_snapshot.clone(), tab_size);
|
||||
let (tab_map, _) = TabMap::new(inlay_snapshot.clone(), tab_size);
|
||||
let tabs_snapshot = tab_map.set_max_expansion_column(32);
|
||||
|
||||
let text = text::Rope::from(tabs_snapshot.text().as_str());
|
||||
|
@ -805,7 +793,7 @@ mod tests {
|
|||
);
|
||||
|
||||
let mut actual_summary = tabs_snapshot.text_summary_for_range(start..end);
|
||||
if tab_size.get() > 1 && editor_addition_snapshot.text().contains('\t') {
|
||||
if tab_size.get() > 1 && inlay_snapshot.text().contains('\t') {
|
||||
actual_summary.longest_row = expected_summary.longest_row;
|
||||
actual_summary.longest_row_chars = expected_summary.longest_row_chars;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use super::{
|
||||
editor_addition_map::EditorAdditionBufferRows,
|
||||
inlay_map::InlayBufferRows,
|
||||
tab_map::{self, TabEdit, TabPoint, TabSnapshot},
|
||||
TextHighlights,
|
||||
};
|
||||
|
@ -65,7 +65,7 @@ pub struct WrapChunks<'a> {
|
|||
|
||||
#[derive(Clone)]
|
||||
pub struct WrapBufferRows<'a> {
|
||||
input_buffer_rows: EditorAdditionBufferRows<'a>,
|
||||
input_buffer_rows: InlayBufferRows<'a>,
|
||||
input_buffer_row: Option<u32>,
|
||||
output_row: u32,
|
||||
soft_wrapped: bool,
|
||||
|
@ -762,17 +762,17 @@ impl WrapSnapshot {
|
|||
let mut prev_fold_row = 0;
|
||||
for display_row in 0..=self.max_point().row() {
|
||||
let tab_point = self.to_tab_point(WrapPoint::new(display_row, 0));
|
||||
let editor_addition_point = self
|
||||
let inlay_point = self
|
||||
.tab_snapshot
|
||||
.to_editor_addition_point(tab_point, Bias::Left)
|
||||
.to_inlay_point(tab_point, Bias::Left)
|
||||
.0;
|
||||
let suggestion_point = self
|
||||
.tab_snapshot
|
||||
.editor_addition_snapshot
|
||||
.to_suggestion_point(editor_addition_point, Bias::Left);
|
||||
.inlay_snapshot
|
||||
.to_suggestion_point(inlay_point, Bias::Left);
|
||||
let fold_point = self
|
||||
.tab_snapshot
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.suggestion_snapshot
|
||||
.to_fold_point(suggestion_point);
|
||||
if fold_point.row() == prev_fold_row && display_row != 0 {
|
||||
|
@ -781,7 +781,7 @@ impl WrapSnapshot {
|
|||
let buffer_point = fold_point.to_buffer_point(
|
||||
&self
|
||||
.tab_snapshot
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.suggestion_snapshot
|
||||
.fold_snapshot,
|
||||
);
|
||||
|
@ -1049,8 +1049,7 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::{
|
||||
display_map::{
|
||||
editor_addition_map::EditorAdditionMap, fold_map::FoldMap,
|
||||
suggestion_map::SuggestionMap, tab_map::TabMap,
|
||||
fold_map::FoldMap, inlay_map::InlayMap, suggestion_map::SuggestionMap, tab_map::TabMap,
|
||||
},
|
||||
MultiBuffer,
|
||||
};
|
||||
|
@ -1106,13 +1105,9 @@ mod tests {
|
|||
log::info!("FoldMap text: {:?}", fold_snapshot.text());
|
||||
let (suggestion_map, suggestion_snapshot) = SuggestionMap::new(fold_snapshot.clone());
|
||||
log::info!("SuggestionMap text: {:?}", suggestion_snapshot.text());
|
||||
let (editor_addition_map, editors_additions_snapshot) =
|
||||
EditorAdditionMap::new(suggestion_snapshot.clone());
|
||||
log::info!(
|
||||
"EditorAdditionsMap text: {:?}",
|
||||
editors_additions_snapshot.text()
|
||||
);
|
||||
let (tab_map, _) = TabMap::new(editors_additions_snapshot.clone(), tab_size);
|
||||
let (inlay_map, inlay_snapshot) = InlayMap::new(suggestion_snapshot.clone());
|
||||
log::info!("InlaysMap text: {:?}", inlay_snapshot.text());
|
||||
let (tab_map, _) = TabMap::new(inlay_snapshot.clone(), tab_size);
|
||||
let tabs_snapshot = tab_map.set_max_expansion_column(32);
|
||||
log::info!("TabMap text: {:?}", tabs_snapshot.text());
|
||||
|
||||
|
@ -1160,10 +1155,10 @@ mod tests {
|
|||
for (fold_snapshot, fold_edits) in fold_map.randomly_mutate(&mut rng) {
|
||||
let (suggestion_snapshot, suggestion_edits) =
|
||||
suggestion_map.sync(fold_snapshot, fold_edits);
|
||||
let (editor_addition_snapshot, editor_addition_edits) =
|
||||
editor_addition_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (inlay_snapshot, inlay_edits) =
|
||||
inlay_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (tabs_snapshot, tab_edits) =
|
||||
tab_map.sync(editor_addition_snapshot, editor_addition_edits, tab_size);
|
||||
tab_map.sync(inlay_snapshot, inlay_edits, tab_size);
|
||||
let (mut snapshot, wrap_edits) =
|
||||
wrap_map.update(cx, |map, cx| map.sync(tabs_snapshot, tab_edits, cx));
|
||||
snapshot.check_invariants();
|
||||
|
@ -1174,10 +1169,10 @@ mod tests {
|
|||
40..=59 => {
|
||||
let (suggestion_snapshot, suggestion_edits) =
|
||||
suggestion_map.randomly_mutate(&mut rng);
|
||||
let (editor_addition_snapshot, editor_addition_edits) =
|
||||
editor_addition_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (inlay_snapshot, inlay_edits) =
|
||||
inlay_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (tabs_snapshot, tab_edits) =
|
||||
tab_map.sync(editor_addition_snapshot, editor_addition_edits, tab_size);
|
||||
tab_map.sync(inlay_snapshot, inlay_edits, tab_size);
|
||||
let (mut snapshot, wrap_edits) =
|
||||
wrap_map.update(cx, |map, cx| map.sync(tabs_snapshot, tab_edits, cx));
|
||||
snapshot.check_invariants();
|
||||
|
@ -1201,10 +1196,10 @@ mod tests {
|
|||
let (suggestion_snapshot, suggestion_edits) =
|
||||
suggestion_map.sync(fold_snapshot, fold_edits);
|
||||
log::info!("SuggestionMap text: {:?}", suggestion_snapshot.text());
|
||||
let (editor_addition_snapshot, editor_addition_edits) =
|
||||
editor_addition_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (inlay_snapshot, inlay_edits) =
|
||||
inlay_map.sync(suggestion_snapshot, suggestion_edits);
|
||||
let (tabs_snapshot, tab_edits) =
|
||||
tab_map.sync(editor_addition_snapshot, editor_addition_edits, tab_size);
|
||||
tab_map.sync(inlay_snapshot, inlay_edits, tab_size);
|
||||
log::info!("TabMap text: {:?}", tabs_snapshot.text());
|
||||
|
||||
let unwrapped_text = tabs_snapshot.text();
|
||||
|
@ -1252,7 +1247,7 @@ mod tests {
|
|||
if tab_size.get() == 1
|
||||
|| !wrapped_snapshot
|
||||
.tab_snapshot
|
||||
.editor_addition_snapshot
|
||||
.inlay_snapshot
|
||||
.text()
|
||||
.contains('\t')
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue