From 4d76162da897c91bef56aaba639fadaa580f8b70 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 9 Jun 2023 11:04:36 +0300 Subject: [PATCH] Report the edits per transform summary generated Co-Authored-By: Antonio Scandurra --- crates/editor/src/display_map/inlay_map.rs | 26 +++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index 529b056eaf2cb59cce376f819df40c6ef6364125..f5c9bbfb4e14f325aa5db16d4a1e8d438010e126 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -297,12 +297,12 @@ impl InlayMap { transform_end += cursor.end(&()) - suggestion_edit.old.end; cursor.next(&()); } - new_transforms.push( - Transform::Isomorphic(suggestion_snapshot.text_summary_for_range( + push_isomorphic( + &mut new_transforms, + suggestion_snapshot.text_summary_for_range( suggestion_snapshot.to_point(transform_start) ..suggestion_snapshot.to_point(transform_end), - )), - &(), + ), ); } @@ -549,7 +549,7 @@ impl InlaySnapshot { match bias { Bias::Left => cursor.end(&()), - Bias::Right => cursor.start(), + Bias::Right => *cursor.start(), } } @@ -664,6 +664,22 @@ impl InlaySnapshot { } } +fn push_isomorphic(sum_tree: &mut SumTree, summary: TextSummary) { + let mut summary = Some(summary); + sum_tree.update_last( + |transform| { + if let Transform::Isomorphic(transform) = transform { + *transform += summary.take().unwrap(); + } + }, + &(), + ); + + if let Some(summary) = summary { + sum_tree.push(Transform::Isomorphic(summary), &()); + } +} + #[cfg(test)] mod tests { use super::*;