diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs index 92a4ba097f21d1f5894235bb2356c7ded9413359..eca7ae359a3ebafbbe13316bb757c1fbfc7f72ce 100644 --- a/crates/diagnostics/src/diagnostics.rs +++ b/crates/diagnostics/src/diagnostics.rs @@ -491,7 +491,7 @@ impl ProjectDiagnosticsEditor { cx: &mut Context, ) -> Task> { 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 max_severity = if self.include_warnings { @@ -602,7 +602,6 @@ impl ProjectDiagnosticsEditor { cx, ) .await; - buffer_snapshot = cx.update(|_, cx| buffer.read(cx).snapshot())?; let initial_range = buffer_snapshot.anchor_after(b.initial_range.start) ..buffer_snapshot.anchor_before(b.initial_range.end); let excerpt_range = ExcerptRange { @@ -1010,11 +1009,14 @@ async fn heuristic_syntactic_expand( snapshot: BufferSnapshot, cx: &mut AsyncApp, ) -> Option> { + 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; if input_row_count > max_row_count { return None; } + let input_range = start..end; // If the outline node contains the diagnostic and is small enough, just use that. let outline_range = snapshot.outline_range_containing(input_range.clone()); if let Some(outline_range) = outline_range.clone() { diff --git a/crates/multi_buffer/src/path_key.rs b/crates/multi_buffer/src/path_key.rs index 56f28d26642439f7869bad714a8b3191dd4edbec..926ceff202837d13fe14350ee0334cbf4036bd89 100644 --- a/crates/multi_buffer/src/path_key.rs +++ b/crates/multi_buffer/src/path_key.rs @@ -288,7 +288,6 @@ impl MultiBuffer { .get(&path) .cloned() .unwrap_or_default(); - let mut new_iter = new.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 to_remove.sort_by_cached_key(|&id| snapshot.excerpt_locator_for_id(id)); self.remove_excerpts(to_remove, cx); + if excerpt_ids.is_empty() { self.excerpts_by_path.remove(&path); } else { for excerpt_id in &excerpt_ids { self.paths_by_excerpt.insert(*excerpt_id, path.clone()); } - self.excerpts_by_path - .insert(path, excerpt_ids.iter().dedup().cloned().collect()); + let snapshot = &*self.snapshot.get_mut(); + 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)