Skip to content

Commit

Permalink
Display highest severity diagnostic in gutter (helix-editor#2835)
Browse files Browse the repository at this point in the history
* Display highest severity diagnostic in gutter

* Improve gutter diagnostic performance

Very slight improvement (doesn't really make a difference), iterates over the diagnostics of the line
once instead of twice.

* Add comment justifying unwrap
  • Loading branch information
A-Walrus authored Jun 21, 2022
1 parent 009f8c4 commit 43027d9
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion helix-view/src/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,18 @@ pub fn diagnostic<'doc>(
Box::new(move |line: usize, _selected: bool, out: &mut String| {
use helix_core::diagnostic::Severity;
if let Ok(index) = diagnostics.binary_search_by_key(&line, |d| d.line) {
let diagnostic = &diagnostics[index];
let after = diagnostics[index..].iter().take_while(|d| d.line == line);

let before = diagnostics[..index]
.iter()
.rev()
.take_while(|d| d.line == line);

let diagnostics_on_line = after.chain(before);

// This unwrap is safe because the iterator cannot be empty as it contains at least the item found by the binary search.
let diagnostic = diagnostics_on_line.max_by_key(|d| d.severity).unwrap();

write!(out, "●").unwrap();
return Some(match diagnostic.severity {
Some(Severity::Error) => error,
Expand Down

0 comments on commit 43027d9

Please sign in to comment.