@@ -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)),