From a794cbc90bcf03772b3bcbb9402244ff5d13a920 Mon Sep 17 00:00:00 2001 From: "zed-zippy[bot]" <234243425+zed-zippy[bot]@users.noreply.github.com> Date: Mon, 9 Mar 2026 08:47:52 +0000 Subject: [PATCH] editor: Prevent panic in `lsp_symbols_at_cursor` with diff hunks handling (#51077) (cherry-pick to preview) (#51079) Cherry-pick of #51077 to preview ---- Fixes ZED-5M9 No test as I couldn't quite reproduce this, as the cause is mostly a guess Release Notes: - Fixed a panic in `lsp_symbols_at_cursor` when dealing with diff hunks Co-authored-by: Lukas Wirth --- crates/auto_update/src/auto_update.rs | 16 ++++------------ crates/editor/src/document_symbols.rs | 3 +++ crates/rope/src/rope.rs | 18 ++++++++++++++---- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/crates/auto_update/src/auto_update.rs b/crates/auto_update/src/auto_update.rs index 53fac7beac2475d06f4a0f886536942308f9976c..33cc1006792dbcfdb1be7b08423870e8827ef1e5 100644 --- a/crates/auto_update/src/auto_update.rs +++ b/crates/auto_update/src/auto_update.rs @@ -212,18 +212,10 @@ pub fn init(client: Arc, cx: &mut App) { } pub fn check(_: &Check, window: &mut Window, cx: &mut App) { - if let Some(message) = option_env!("ZED_UPDATE_EXPLANATION") { - drop(window.prompt( - gpui::PromptLevel::Info, - "Zed was installed via a package manager.", - Some(message), - &["Ok"], - cx, - )); - return; - } - - if let Ok(message) = env::var("ZED_UPDATE_EXPLANATION") { + if let Some(message) = option_env!("ZED_UPDATE_EXPLANATION") + .map(ToOwned::to_owned) + .or_else(|| env::var("ZED_UPDATE_EXPLANATION").ok()) + { drop(window.prompt( gpui::PromptLevel::Info, "Zed was installed via a package manager.", diff --git a/crates/editor/src/document_symbols.rs b/crates/editor/src/document_symbols.rs index 927ef34690477ba436bf70a66b3f9f45b8864587..94d53eb19621cbe4d84734e2e77286180a59adf7 100644 --- a/crates/editor/src/document_symbols.rs +++ b/crates/editor/src/document_symbols.rs @@ -77,6 +77,9 @@ impl Editor { let excerpt = multi_buffer_snapshot.excerpt_containing(cursor..cursor)?; let excerpt_id = excerpt.id(); let buffer_id = excerpt.buffer_id(); + if Some(buffer_id) != cursor.text_anchor.buffer_id { + return None; + } let buffer = self.buffer.read(cx).buffer(buffer_id)?; let buffer_snapshot = buffer.read(cx).snapshot(); let cursor_text_anchor = cursor.text_anchor; diff --git a/crates/rope/src/rope.rs b/crates/rope/src/rope.rs index 5b599bad51c2f571cca11625be0b290e7e748504..04a38168dfa32bcbf96a3ee5062fe6ab4c62521b 100644 --- a/crates/rope/src/rope.rs +++ b/crates/rope/src/rope.rs @@ -693,16 +693,21 @@ impl<'a> Cursor<'a> { } pub fn seek_forward(&mut self, end_offset: usize) { - debug_assert!(end_offset >= self.offset); + assert!( + end_offset >= self.offset, + "cannot seek backward from {} to {}", + self.offset, + end_offset + ); self.chunks.seek_forward(&end_offset, Bias::Right); self.offset = end_offset; } pub fn slice(&mut self, end_offset: usize) -> Rope { - debug_assert!( + assert!( end_offset >= self.offset, - "cannot slice backwards from {} to {}", + "cannot slice backward from {} to {}", self.offset, end_offset ); @@ -730,7 +735,12 @@ impl<'a> Cursor<'a> { } pub fn summary(&mut self, end_offset: usize) -> D { - debug_assert!(end_offset >= self.offset); + assert!( + end_offset >= self.offset, + "cannot summarize backward from {} to {}", + self.offset, + end_offset + ); let mut summary = D::zero(()); if let Some(start_chunk) = self.chunks.item() {