Skip to content

Commit 5f4f171

Browse files
Fix debug assertion for diagnostic sort order (#4319)
The debug assertion that document diagnostics are sorted incorrectly panics for cases like `[161..164, 162..162]`. The merging behavior in the following lines that relies on the assertion only needs the input ranges to be sorted by `range.start`, so this change simplifies the assertion to only catch violations of that assumption.
1 parent 63fe423 commit 5f4f171

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

helix-term/src/ui/editor.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,7 @@ impl EditorView {
302302
let mut warning_vec = Vec::new();
303303
let mut error_vec = Vec::new();
304304

305-
let diagnostics = doc.diagnostics();
306-
307-
// Diagnostics must be sorted by range. Otherwise, the merge strategy
308-
// below would not be accurate.
309-
debug_assert!(diagnostics
310-
.windows(2)
311-
.all(|window| window[0].range.start <= window[1].range.start
312-
&& window[0].range.end <= window[1].range.end));
313-
314-
for diagnostic in diagnostics {
305+
for diagnostic in doc.diagnostics() {
315306
// Separate diagnostics into different Vecs by severity.
316307
let (vec, scope) = match diagnostic.severity {
317308
Some(Severity::Info) => (&mut info_vec, info),
@@ -325,6 +316,11 @@ impl EditorView {
325316
// merge the two together. Otherwise push a new span.
326317
match vec.last_mut() {
327318
Some((_, range)) if diagnostic.range.start <= range.end => {
319+
// This branch merges overlapping diagnostics, assuming that the current
320+
// diagnostic starts on range.start or later. If this assertion fails,
321+
// we will discard some part of `diagnostic`. This implies that
322+
// `doc.diagnostics()` is not sorted by `diagnostic.range`.
323+
debug_assert!(range.start <= diagnostic.range.start);
328324
range.end = diagnostic.range.end.max(range.end)
329325
}
330326
_ => vec.push((scope, diagnostic.range.start..diagnostic.range.end)),

0 commit comments

Comments
 (0)