Skip to content

Commit

Permalink
consistent diagnostic sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalkuthe committed Jun 20, 2023
1 parent 7b2ff05 commit 352cad6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,9 @@ impl Application {

// Sort diagnostics first by severity and then by line numbers.
// Note: The `lsp::DiagnosticSeverity` enum is already defined in decreasing order
diagnostics.sort_unstable_by_key(|(d, _)| (d.severity, d.range.start));
diagnostics.sort_unstable_by_key(|(d, server_id)| {
(d.severity, d.range.start, *server_id)
});
}
Notification::ShowMessage(params) => {
log::warn!("unhandled window/showMessage: {:?}", params);
Expand Down
18 changes: 14 additions & 4 deletions helix-view/src/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,8 +1135,13 @@ impl Document {
.max(diagnostic.range.start);
diagnostic.line = self.text.char_to_line(diagnostic.range.start);
}
self.diagnostics
.sort_unstable_by_key(|diagnostic| diagnostic.range);
self.diagnostics.sort_unstable_by_key(|diagnostic| {
(
diagnostic.range,
diagnostic.severity,
diagnostic.language_server_id,
)
});

// Update the inlay hint annotations' positions, helping ensure they are displayed in the proper place
let apply_inlay_hint_changes = |annotations: &mut Rc<[InlineAnnotation]>| {
Expand Down Expand Up @@ -1632,8 +1637,13 @@ impl Document {
});
}
self.diagnostics.extend(diagnostics);
self.diagnostics
.sort_unstable_by_key(|diagnostic| diagnostic.range);
self.diagnostics.sort_unstable_by_key(|diagnostic| {
(
diagnostic.range,
diagnostic.severity,
diagnostic.language_server_id,
)
});
}

pub fn clear_diagnostics(&mut self, language_server_id: usize) {
Expand Down

0 comments on commit 352cad6

Please sign in to comment.