editor: Prevent panic in lsp_symbols_at_cursor with diff hunks handling (#51077)

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
This commit is contained in:
Lukas Wirth 2026-03-09 09:35:19 +01:00 committed by GitHub
parent 8762b7f503
commit 3f2ddcbca3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 16 deletions

View file

@ -212,18 +212,10 @@ pub fn init(client: Arc<Client>, 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.",

View file

@ -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;

View file

@ -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<D: TextDimension>(&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() {