multi_buffer: Work around another panic bug in path_key (#42920)

Fixes ZED-346 for now until I find the time to dig into this bug
properly

Release Notes:

- Fixed a panic in the diagnostics pane
This commit is contained in:
Lukas Wirth
2025-11-17 22:38:48 +00:00
committed by GitHub
parent 6bea23e990
commit 2c7bcfcb7b
2 changed files with 9 additions and 5 deletions
+4 -2
View File
@@ -491,7 +491,7 @@ impl ProjectDiagnosticsEditor {
cx: &mut Context<Self>, cx: &mut Context<Self>,
) -> Task<Result<()>> { ) -> Task<Result<()>> {
let was_empty = self.multibuffer.read(cx).is_empty(); let was_empty = self.multibuffer.read(cx).is_empty();
let mut buffer_snapshot = buffer.read(cx).snapshot(); let buffer_snapshot = buffer.read(cx).snapshot();
let buffer_id = buffer_snapshot.remote_id(); let buffer_id = buffer_snapshot.remote_id();
let max_severity = if self.include_warnings { let max_severity = if self.include_warnings {
@@ -602,7 +602,6 @@ impl ProjectDiagnosticsEditor {
cx, cx,
) )
.await; .await;
buffer_snapshot = cx.update(|_, cx| buffer.read(cx).snapshot())?;
let initial_range = buffer_snapshot.anchor_after(b.initial_range.start) let initial_range = buffer_snapshot.anchor_after(b.initial_range.start)
..buffer_snapshot.anchor_before(b.initial_range.end); ..buffer_snapshot.anchor_before(b.initial_range.end);
let excerpt_range = ExcerptRange { let excerpt_range = ExcerptRange {
@@ -1010,11 +1009,14 @@ async fn heuristic_syntactic_expand(
snapshot: BufferSnapshot, snapshot: BufferSnapshot,
cx: &mut AsyncApp, cx: &mut AsyncApp,
) -> Option<RangeInclusive<BufferRow>> { ) -> Option<RangeInclusive<BufferRow>> {
let start = snapshot.clip_point(input_range.start, Bias::Right);
let end = snapshot.clip_point(input_range.end, Bias::Left);
let input_row_count = input_range.end.row - input_range.start.row; let input_row_count = input_range.end.row - input_range.start.row;
if input_row_count > max_row_count { if input_row_count > max_row_count {
return None; return None;
} }
let input_range = start..end;
// If the outline node contains the diagnostic and is small enough, just use that. // If the outline node contains the diagnostic and is small enough, just use that.
let outline_range = snapshot.outline_range_containing(input_range.clone()); let outline_range = snapshot.outline_range_containing(input_range.clone());
if let Some(outline_range) = outline_range.clone() { if let Some(outline_range) = outline_range.clone() {
+5 -3
View File
@@ -288,7 +288,6 @@ impl MultiBuffer {
.get(&path) .get(&path)
.cloned() .cloned()
.unwrap_or_default(); .unwrap_or_default();
let mut new_iter = new.into_iter().peekable(); let mut new_iter = new.into_iter().peekable();
let mut existing_iter = existing.into_iter().peekable(); let mut existing_iter = existing.into_iter().peekable();
@@ -413,14 +412,17 @@ impl MultiBuffer {
// todo(lw): There is a logic bug somewhere that causes the to_remove vector to be not ordered correctly // todo(lw): There is a logic bug somewhere that causes the to_remove vector to be not ordered correctly
to_remove.sort_by_cached_key(|&id| snapshot.excerpt_locator_for_id(id)); to_remove.sort_by_cached_key(|&id| snapshot.excerpt_locator_for_id(id));
self.remove_excerpts(to_remove, cx); self.remove_excerpts(to_remove, cx);
if excerpt_ids.is_empty() { if excerpt_ids.is_empty() {
self.excerpts_by_path.remove(&path); self.excerpts_by_path.remove(&path);
} else { } else {
for excerpt_id in &excerpt_ids { for excerpt_id in &excerpt_ids {
self.paths_by_excerpt.insert(*excerpt_id, path.clone()); self.paths_by_excerpt.insert(*excerpt_id, path.clone());
} }
self.excerpts_by_path let snapshot = &*self.snapshot.get_mut();
.insert(path, excerpt_ids.iter().dedup().cloned().collect()); let mut excerpt_ids: Vec<_> = excerpt_ids.iter().dedup().cloned().collect();
excerpt_ids.sort_by_cached_key(|&id| snapshot.excerpt_locator_for_id(id));
self.excerpts_by_path.insert(path, excerpt_ids);
} }
(excerpt_ids, added_a_new_excerpt) (excerpt_ids, added_a_new_excerpt)