editor: Support walking through overlapping diagnostics (#11139)
While looking into how to implement #4901, noticed that the current `Goto next/previous diagnostic` behaved a bit weirdly. That is, when there are multiple errors that have overlapping ranges, only the first one can be chosen to be active by the `go_to_diagnostic_impl`. ### Previous behavior: https://github.com/zed-industries/zed/assets/71292737/95897675-f5ee-40e5-869f-0a40066eb8e3 Doesn't go through all the diagnostics, and going backwards and forwards doesn't show the same diagnostic always. ### New behavior: https://github.com/zed-industries/zed/assets/71292737/81f7945a-7ad8-4a34-b286-cc2799b10500 Should always go through the diagnostics in a consistent manner. Release Notes: * Improved the behavioral consistency of "Go to Next/Previous Diagnostic"
This commit is contained in:
parent
c71cfd5da4
commit
b8a83443ac
2 changed files with 45 additions and 15 deletions
|
@ -3159,7 +3159,21 @@ impl BufferSnapshot {
|
|||
.iter_mut()
|
||||
.enumerate()
|
||||
.flat_map(|(ix, iter)| Some((ix, iter.peek()?)))
|
||||
.min_by(|(_, a), (_, b)| a.range.start.cmp(&b.range.start))?;
|
||||
.min_by(|(_, a), (_, b)| {
|
||||
let cmp = a
|
||||
.range
|
||||
.start
|
||||
.cmp(&b.range.start)
|
||||
// when range is equal, sort by diagnostic severity
|
||||
.then(a.diagnostic.severity.cmp(&b.diagnostic.severity))
|
||||
// and stabilize order with group_id
|
||||
.then(a.diagnostic.group_id.cmp(&b.diagnostic.group_id));
|
||||
if reversed {
|
||||
cmp.reverse()
|
||||
} else {
|
||||
cmp
|
||||
}
|
||||
})?;
|
||||
iterators[next_ix].next()
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue