aboutsummaryrefslogtreecommitdiff
path: root/helix-view/src
diff options
context:
space:
mode:
authorA-Walrus2022-06-21 02:39:43 +0000
committerGitHub2022-06-21 02:39:43 +0000
commit43027d91046f79d6dc495b351cdcbfd3819cd9e1 (patch)
tree796e8bde77116c8eb5a6c9487e6fc252c12daa5a /helix-view/src
parent009f8c4d3bdf56c9c5b0ba9489864d4d242a6e01 (diff)
Display highest severity diagnostic in gutter (#2835)
* 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
Diffstat (limited to 'helix-view/src')
-rw-r--r--helix-view/src/gutter.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs
index eb6796be..05fec758 100644
--- a/helix-view/src/gutter.rs
+++ b/helix-view/src/gutter.rs
@@ -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,