Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Fix panic in Diagnostics (#11066)

Conrad Irwine0644de90e22
diff --git a/crates/diagnostics/src/diagnostics.rs b/crates/diagnostics/src/diagnostics.rs
index d06ff824fb2..0fbacf4743f 100644
--- a/crates/diagnostics/src/diagnostics.rs
+++ b/crates/diagnostics/src/diagnostics.rs
@@ -859,20 +859,25 @@ fn diagnostic_header_renderer(diagnostic: Diagnostic) -> RenderBlock {
})
}
-fn compare_diagnostics<L: language::ToOffset, R: language::ToOffset>(
- lhs: &DiagnosticEntry<L>,
- rhs: &DiagnosticEntry<R>,
+fn compare_diagnostics(
+ old: &DiagnosticEntry<language::Anchor>,
+ new: &DiagnosticEntry<language::Anchor>,
snapshot: &language::BufferSnapshot,
) -> Ordering {
- lhs.range
+ use language::ToOffset;
+ // The old diagnostics may point to a previously open Buffer for this file.
+ if !old.range.start.is_valid(snapshot) {
+ return Ordering::Greater;
+ }
+ old.range
.start
.to_offset(snapshot)
- .cmp(&rhs.range.start.to_offset(snapshot))
+ .cmp(&new.range.start.to_offset(snapshot))
.then_with(|| {
- lhs.range
+ old.range
.end
.to_offset(snapshot)
- .cmp(&rhs.range.end.to_offset(snapshot))
+ .cmp(&new.range.end.to_offset(snapshot))
})
- .then_with(|| lhs.diagnostic.message.cmp(&rhs.diagnostic.message))
+ .then_with(|| old.diagnostic.message.cmp(&new.diagnostic.message))
}