From 52099b45e7d80ae1b94b088c98ec623c52daf960 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Sat, 7 Feb 2026 01:22:28 +0200 Subject: [PATCH] Fix panic with LSP folds on disappearing excerpts (#48649) Follow-up of https://github.com/zed-industries/zed/pull/48611 Release Notes: - N/A --- crates/editor/src/display_map/crease_map.rs | 33 ++++++++------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/crates/editor/src/display_map/crease_map.rs b/crates/editor/src/display_map/crease_map.rs index 8f4a3781f4f335f1a3e61ec5a19818661a7c6ea5..7c81562b7448bdb53bd0dd641eada92dff527aac 100644 --- a/crates/editor/src/display_map/crease_map.rs +++ b/crates/editor/src/display_map/crease_map.rs @@ -1,4 +1,4 @@ -use collections::HashMap; +use collections::{HashMap, HashSet}; use gpui::{AnyElement, IntoElement}; use multi_buffer::{Anchor, AnchorRangeExt, MultiBufferRow, MultiBufferSnapshot, ToPoint}; use serde::{Deserialize, Serialize}; @@ -331,34 +331,25 @@ impl CreaseMap { snapshot: &MultiBufferSnapshot, ) -> Vec<(CreaseId, Range)> { let mut removals = Vec::new(); + let mut ids_to_remove = HashSet::default(); for id in ids { if let Some(range) = self.id_to_range.remove(&id) { - removals.push((id, range.clone())); + ids_to_remove.insert(id); + removals.push((id, range)); } } - removals.sort_unstable_by(|(a_id, a_range), (b_id, b_range)| { - AnchorRangeExt::cmp(a_range, b_range, snapshot).then(b_id.cmp(a_id)) - }); - self.snapshot.creases = { - let mut new_creases = SumTree::new(snapshot); - let mut cursor = self.snapshot.creases.cursor::(snapshot); - - for (id, range) in &removals { - new_creases.append(cursor.slice(range, Bias::Left), snapshot); - while let Some(item) = cursor.item() { - cursor.next(); - if item.id == *id { - break; - } else { + if !ids_to_remove.is_empty() { + self.snapshot.creases = { + let mut new_creases = SumTree::new(snapshot); + for item in self.snapshot.creases.iter() { + if !ids_to_remove.contains(&item.id) { new_creases.push(item.clone(), snapshot); } } - } - - new_creases.append(cursor.suffix(), snapshot); - new_creases - }; + new_creases + }; + } removals }