@@ -302,16 +302,7 @@ impl EditorView {
302 let mut warning_vec = Vec::new();
302 let mut warning_vec = Vec::new();
303 let mut error_vec = Vec::new();
303 let mut error_vec = Vec::new();
305− let diagnostics = doc.diagnostics();
307− // Diagnostics must be sorted by range. Otherwise, the merge strategy
308− // below would not be accurate.
309− debug_assert!(diagnostics
311− .all(|window| window[0].range.start <= window[1].range.start
312− && window[0].range.end <= window[1].range.end));
314− for diagnostic in diagnostics {
305+ for diagnostic in doc.diagnostics() {
315 // Separate diagnostics into different Vecs by severity.
306 // Separate diagnostics into different Vecs by severity.
316 let (vec, scope) = match diagnostic.severity {
307 let (vec, scope) = match diagnostic.severity {
317 Some(Severity::Info) => (&mut info_vec, info),
308 Some(Severity::Info) => (&mut info_vec, info),
@@ -325,6 +316,11 @@ impl EditorView {
325 // merge the two together. Otherwise push a new span.
316 // merge the two together. Otherwise push a new span.
326 match vec.last_mut() {
317 match vec.last_mut() {
327 Some((_, range)) if diagnostic.range.start <= range.end => {
318 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);
328 range.end = diagnostic.range.end.max(range.end)
324 range.end = diagnostic.range.end.max(range.end)
330 _ => vec.push((scope, diagnostic.range.start..diagnostic.range.end)),
326 _ => vec.push((scope, diagnostic.range.start..diagnostic.range.end)),