From bec9c26fa2256bfbaf10f3343c1cc56c00a84966 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Wed, 14 Jun 2023 18:59:27 +0300 Subject: [PATCH] Fix more inlay_map corner cases and hangings Co-Authored-By: Antonio Scandurra --- crates/editor/src/display_map/inlay_map.rs | 21 +++++++++++++++++++-- crates/editor/src/multi_buffer/anchor.rs | 13 ++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/crates/editor/src/display_map/inlay_map.rs b/crates/editor/src/display_map/inlay_map.rs index cdc06fc66b..9818ad0aab 100644 --- a/crates/editor/src/display_map/inlay_map.rs +++ b/crates/editor/src/display_map/inlay_map.rs @@ -253,7 +253,7 @@ impl InlayMap { pub fn sync( &mut self, suggestion_snapshot: SuggestionSnapshot, - suggestion_edits: Vec, + mut suggestion_edits: Vec, ) -> (InlaySnapshot, Vec) { let mut snapshot = self.snapshot.lock(); @@ -262,6 +262,22 @@ impl InlayMap { new_snapshot.version += 1; } + if suggestion_snapshot + .buffer_snapshot() + .trailing_excerpt_update_count() + != snapshot + .suggestion_snapshot + .buffer_snapshot() + .trailing_excerpt_update_count() + { + if suggestion_edits.is_empty() { + suggestion_edits.push(Edit { + old: snapshot.suggestion_snapshot.len()..snapshot.suggestion_snapshot.len(), + new: suggestion_snapshot.len()..suggestion_snapshot.len(), + }); + } + } + let mut inlay_edits = Patch::default(); let mut new_transforms = SumTree::new(); let mut cursor = snapshot @@ -393,7 +409,8 @@ impl InlayMap { to_remove: Vec, to_insert: Vec<(InlayId, InlayProperties)>, ) -> (InlaySnapshot, Vec) { - let snapshot = self.snapshot.lock(); + let mut snapshot = self.snapshot.lock(); + snapshot.version += 1; let mut edits = BTreeSet::new(); for (id, properties) in to_insert { diff --git a/crates/editor/src/multi_buffer/anchor.rs b/crates/editor/src/multi_buffer/anchor.rs index 091196e8d0..1be4dc2dfb 100644 --- a/crates/editor/src/multi_buffer/anchor.rs +++ b/crates/editor/src/multi_buffer/anchor.rs @@ -90,15 +90,10 @@ impl Anchor { if *self == Anchor::min() || *self == Anchor::max() { true } else if let Some(excerpt) = snapshot.excerpt(self.excerpt_id) { - self.text_anchor.is_valid(&excerpt.buffer) - && self - .text_anchor - .cmp(&excerpt.range.context.start, &excerpt.buffer) - .is_ge() - && self - .text_anchor - .cmp(&excerpt.range.context.end, &excerpt.buffer) - .is_le() + excerpt.contains(self) + && (self.text_anchor == excerpt.range.context.start + || self.text_anchor == excerpt.range.context.end + || self.text_anchor.is_valid(&excerpt.buffer)) } else { false }