Check validity of new.range too (#12781)

Conrad Irwin created

I'm not certain yet how it could be invalid, but we are still seeing
panics here.

Release Notes:

- Fixed a panic when opening the diagnostics view

Change summary

crates/diagnostics/src/diagnostics.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)

Detailed changes

crates/diagnostics/src/diagnostics.rs 🔗

@@ -867,10 +867,12 @@ fn compare_diagnostics(
     snapshot: &language::BufferSnapshot,
 ) -> Ordering {
     use language::ToOffset;
-    // The old diagnostics may point to a previously open Buffer for this file.
-    if !old.range.start.is_valid(snapshot) {
+
+    // The diagnostics may point to a previously open Buffer for this file.
+    if !old.range.start.is_valid(snapshot) || !new.range.start.is_valid(snapshot) {
         return Ordering::Greater;
     }
+
     old.range
         .start
         .to_offset(snapshot)