mirror of https://github.com/astral-sh/ruff
Add support for sorting diagnostics without a range (#20257)
- Update ruff ordering compare to work with optional ranges (treating them as starting from zero)
This commit is contained in:
parent
5d52902e18
commit
a27c64811e
|
|
@ -501,13 +501,18 @@ impl Diagnostic {
|
||||||
|
|
||||||
/// Returns the ordering of diagnostics based on the start of their ranges, if they have any.
|
/// 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
|
/// Panics if either diagnostic has no primary span, or if its file is not a `SourceFile`.
|
||||||
/// not a `SourceFile`.
|
|
||||||
pub fn ruff_start_ordering(&self, other: &Self) -> std::cmp::Ordering {
|
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_ruff_source_file(),
|
||||||
other.expect_range().start(),
|
other.range().map(|r| r.start()),
|
||||||
))
|
);
|
||||||
|
|
||||||
|
a.cmp(&b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue