summaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorPhilipp Mildenberger2023-03-28 02:15:03 +0000
committerPhilipp Mildenberger2023-05-18 19:58:17 +0000
commit2a21b939c432e4b5a186df780a1e97d20ff53120 (patch)
tree7d94104c173591384912cec4748f8001b6eb2c56 /helix-view
parent93fd79a949f0fcaa97fa30f841d90c6c1c3f68de (diff)
Fix crash with filtered diagnostics in gutter (e.g. when diagnostics aren't visible)
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/gutter.rs19
1 files changed, 9 insertions, 10 deletions
diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs
index 8c8abcc3..475ec5a3 100644
--- a/helix-view/src/gutter.rs
+++ b/helix-view/src/gutter.rs
@@ -83,16 +83,15 @@ pub fn diagnostic<'doc>(
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,
- Some(Severity::Warning) | None => warning,
- Some(Severity::Info) => info,
- Some(Severity::Hint) => hint,
- });
+ if let Some(diagnostic) = diagnostics_on_line.max_by_key(|d| d.severity) {
+ write!(out, "●").ok();
+ return Some(match diagnostic.severity {
+ Some(Severity::Error) => error,
+ Some(Severity::Warning) | None => warning,
+ Some(Severity::Info) => info,
+ Some(Severity::Hint) => hint,
+ });
+ }
}
None
},