From a27c64811e37e01592fd58e32c77734aa1297c18 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Fri, 5 Sep 2025 15:23:30 -0700 Subject: [PATCH] Add support for sorting diagnostics without a range (#20257) - Update ruff ordering compare to work with optional ranges (treating them as starting from zero) --- crates/ruff_db/src/diagnostic/mod.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/ruff_db/src/diagnostic/mod.rs b/crates/ruff_db/src/diagnostic/mod.rs index c44dce2116..709dbe42c6 100644 --- a/crates/ruff_db/src/diagnostic/mod.rs +++ b/crates/ruff_db/src/diagnostic/mod.rs @@ -501,13 +501,18 @@ impl Diagnostic { /// Returns the ordering of diagnostics based on the start of their ranges, if they have any. /// - /// Panics if either diagnostic has no primary span, if the span has no range, or if its file is - /// not a `SourceFile`. + /// Panics if either diagnostic has no primary span, or if its file is not a `SourceFile`. pub fn ruff_start_ordering(&self, other: &Self) -> std::cmp::Ordering { - (self.expect_ruff_source_file(), self.expect_range().start()).cmp(&( + let a = ( + self.expect_ruff_source_file(), + self.range().map(|r| r.start()), + ); + let b = ( other.expect_ruff_source_file(), - other.expect_range().start(), - )) + other.range().map(|r| r.start()), + ); + + a.cmp(&b) } }