on master help sign in
Fix crash with filtered diagnostics in gutter (e.g. when diagnostics aren't visible)
2a21b93Philipp Mildenberger
helix-view/src/gutter.rs+9−10
@@ -83,16 +83,15 @@ pub fn diagnostic<'doc>(
83
83
84 let diagnostics_on_line = after.chain(before);
84 let diagnostics_on_line = after.chain(before);
85
85
86− // This unwrap is safe because the iterator cannot be empty as it contains at least the item found by the binary search.
87− let diagnostic = diagnostics_on_line.max_by_key(|d| d.severity).unwrap();
86+ if let Some(diagnostic) = diagnostics_on_line.max_by_key(|d| d.severity) {
88−
89− write!(out, "●").unwrap();
87+ write!(out, "●").ok();
90− return Some(match diagnostic.severity {
88+ return Some(match diagnostic.severity {
91− Some(Severity::Error) => error,
89+ Some(Severity::Error) => error,
92− Some(Severity::Warning) | None => warning,
90+ Some(Severity::Warning) | None => warning,
93− Some(Severity::Info) => info,
91+ Some(Severity::Info) => info,
94− Some(Severity::Hint) => hint,
92+ Some(Severity::Hint) => hint,
95− });
93+ });
94+ }
96 }
95 }
97 None
96 None
98 },
97 },