Skip to content

Commit a27c648

Browse files
authored
Add support for sorting diagnostics without a range (#20257)
- Update ruff ordering compare to work with optional ranges (treating them as starting from zero)
1 parent 5d52902 commit a27c648

File tree

1 file changed

+10
-5
lines changed
  • crates/ruff_db/src/diagnostic

1 file changed

+10
-5
lines changed

crates/ruff_db/src/diagnostic/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,18 @@ impl Diagnostic {
501501

502502
/// Returns the ordering of diagnostics based on the start of their ranges, if they have any.
503503
///
504-
/// Panics if either diagnostic has no primary span, if the span has no range, or if its file is
505-
/// not a `SourceFile`.
504+
/// Panics if either diagnostic has no primary span, or if its file is not a `SourceFile`.
506505
pub fn ruff_start_ordering(&self, other: &Self) -> std::cmp::Ordering {
507-
(self.expect_ruff_source_file(), self.expect_range().start()).cmp(&(
506+
let a = (
507+
self.expect_ruff_source_file(),
508+
self.range().map(|r| r.start()),
509+
);
510+
let b = (
508511
other.expect_ruff_source_file(),
509-
other.expect_range().start(),
510-
))
512+
other.range().map(|r| r.start()),
513+
);
514+
515+
a.cmp(&b)
511516
}
512517
}
513518

0 commit comments

Comments
 (0)