Skip to content

Commit 568f553

Browse files
committed
Add support for sorting diagnostics without a range
- Update ruff ordering compare to work with optional ranges (treating them as starting from zero)
1 parent a24a4b5 commit 568f553

File tree

1 file changed

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

1 file changed

+11
-5
lines changed

crates/ruff_db/src/diagnostic/mod.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,19 @@ 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+
/// Diagnostics with range of None will be treated as starting at zero.
505+
/// Panics if either diagnostic has no primary span, or if its file is not a `SourceFile`.
506506
pub fn ruff_start_ordering(&self, other: &Self) -> std::cmp::Ordering {
507-
(self.expect_ruff_source_file(), self.expect_range().start()).cmp(&(
507+
let a = (
508+
self.expect_ruff_source_file(),
509+
self.range().map(|r| r.start()).unwrap_or_default(),
510+
);
511+
let b = (
508512
other.expect_ruff_source_file(),
509-
other.expect_range().start(),
510-
))
513+
other.range().map(|r| r.start()).unwrap_or_default(),
514+
);
515+
516+
a.cmp(&b)
511517
}
512518
}
513519

0 commit comments

Comments
 (0)