Simplify inlay hint version handling

This commit is contained in:
Kirill Bulatov
2023-06-29 22:25:48 +03:00
parent d506522eef
commit 7397b8028c
5 changed files with 111 additions and 136 deletions
+2 -4
View File
@@ -1181,8 +1181,7 @@ mod tests {
fold_map.read(buffer_snapshot, subscription.consume().into_inner());
let (suggestion_snapshot, suggestion_edits) =
suggestion_map.sync(fold_snapshot, fold_edits);
let (inlay_snapshot, inlay_edits) =
inlay_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(inlay_snapshot, inlay_edits, 4.try_into().unwrap());
let (wraps_snapshot, wrap_edits) = wrap_map.update(cx, |wrap_map, cx| {
@@ -1396,8 +1395,7 @@ mod tests {
suggestion_map.sync(fold_snapshot, fold_edits);
let (inlay_snapshot, inlay_edits) =
inlay_map.sync(suggestion_snapshot, suggestion_edits);
let (tab_snapshot, tab_edits) =
tab_map.sync(inlay_snapshot, inlay_edits, tab_size);
let (tab_snapshot, tab_edits) = 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)
});
+11 -26
View File
@@ -44,9 +44,7 @@ impl TabMap {
version: old_snapshot.version,
};
if old_snapshot.inlay_snapshot.version
!= new_snapshot.inlay_snapshot.version
{
if old_snapshot.inlay_snapshot.version != new_snapshot.inlay_snapshot.version {
new_snapshot.version += 1;
}
@@ -60,11 +58,10 @@ impl TabMap {
let old_end = old_snapshot
.inlay_snapshot
.to_point(suggestion_edit.old.end);
let old_end_row_successor_offset =
old_snapshot.inlay_snapshot.to_offset(cmp::min(
InlayPoint::new(old_end.row() + 1, 0),
old_snapshot.inlay_snapshot.max_point(),
));
let old_end_row_successor_offset = 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
.inlay_snapshot
.to_point(suggestion_edit.new.end);
@@ -171,12 +168,9 @@ impl TabSnapshot {
pub fn line_len(&self, row: u32) -> u32 {
let max_point = self.max_point();
if row < max_point.row() {
self.to_tab_point(InlayPoint::new(
row,
self.inlay_snapshot.line_len(row),
))
.0
.column
self.to_tab_point(InlayPoint::new(row, self.inlay_snapshot.line_len(row)))
.0
.column
} else {
max_point.column()
}
@@ -331,27 +325,18 @@ impl TabSnapshot {
.inlay_snapshot
.suggestion_snapshot
.to_suggestion_point(fold_point);
let inlay_point = self
.inlay_snapshot
.to_inlay_point(suggestion_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 inlay_point = self.to_inlay_point(point, bias).0;
let suggestion_point = self
.inlay_snapshot
.to_suggestion_point(inlay_point, bias);
let suggestion_point = self.inlay_snapshot.to_suggestion_point(inlay_point, bias);
let fold_point = self
.inlay_snapshot
.suggestion_snapshot
.to_fold_point(suggestion_point);
fold_point.to_buffer_point(
&self
.inlay_snapshot
.suggestion_snapshot
.fold_snapshot,
)
fold_point.to_buffer_point(&self.inlay_snapshot.suggestion_snapshot.fold_snapshot)
}
fn expand_tabs(&self, chars: impl Iterator<Item = char>, column: u32) -> u32 {
+2 -6
View File
@@ -762,10 +762,7 @@ 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 inlay_point = self
.tab_snapshot
.to_inlay_point(tab_point, Bias::Left)
.0;
let inlay_point = self.tab_snapshot.to_inlay_point(tab_point, Bias::Left).0;
let suggestion_point = self
.tab_snapshot
.inlay_snapshot
@@ -1198,8 +1195,7 @@ mod tests {
log::info!("SuggestionMap text: {:?}", suggestion_snapshot.text());
let (inlay_snapshot, inlay_edits) =
inlay_map.sync(suggestion_snapshot, suggestion_edits);
let (tabs_snapshot, tab_edits) =
tab_map.sync(inlay_snapshot, inlay_edits, tab_size);
let (tabs_snapshot, tab_edits) = tab_map.sync(inlay_snapshot, inlay_edits, tab_size);
log::info!("TabMap text: {:?}", tabs_snapshot.text());
let unwrapped_text = tabs_snapshot.text();