aboutsummaryrefslogtreecommitdiff
path: root/helix-view
diff options
context:
space:
mode:
authorPhilipp Mildenberger2023-04-05 18:03:41 +0000
committerPhilipp Mildenberger2023-05-18 20:04:49 +0000
commit656ee24966c17ed505acc2faded2da505e9c7052 (patch)
tree0097e46b1ace3e374b7e3bfcf6bec4a204138a48 /helix-view
parent2b746ea6fa6f7040e3ea51e1386bb914333594f4 (diff)
Simplify gutter diagnostics rendering by using partition_point instead of binary search
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
Diffstat (limited to 'helix-view')
-rw-r--r--helix-view/src/gutter.rs42
1 files changed, 17 insertions, 25 deletions
diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs
index 475ec5a3..d11cbe4d 100644
--- a/helix-view/src/gutter.rs
+++ b/helix-view/src/gutter.rs
@@ -1,6 +1,6 @@
use std::fmt::Write;
-use helix_core::{syntax::LanguageServerFeature, Diagnostic};
+use helix_core::syntax::LanguageServerFeature;
use crate::{
editor::GutterType,
@@ -65,35 +65,27 @@ pub fn diagnostic<'doc>(
return None;
}
use helix_core::diagnostic::Severity;
- if let Ok(index) = diagnostics.binary_search_by_key(&line, |d| d.line) {
- let on_line_and_is_visible = |d: &&Diagnostic| {
+ let first_diag_idx_maybe_on_line = diagnostics.partition_point(|d| d.line < line);
+ if first_diag_idx_maybe_on_line == diagnostics.len() {
+ return None;
+ }
+ let diagnostics_on_line = diagnostics[first_diag_idx_maybe_on_line..]
+ .iter()
+ .take_while(|d| {
d.line == line
&& doc
.language_servers_with_feature(LanguageServerFeature::Diagnostics)
.any(|ls| ls.id() == d.language_server_id)
- };
- let after = diagnostics[index..]
- .iter()
- .take_while(on_line_and_is_visible);
-
- let before = diagnostics[..index]
- .iter()
- .rev()
- .take_while(on_line_and_is_visible);
-
- let diagnostics_on_line = after.chain(before);
-
- 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,
- });
+ });
+ diagnostics_on_line.max_by_key(|d| d.severity).map(|d| {
+ write!(out, "●").ok();
+ match d.severity {
+ Some(Severity::Error) => error,
+ Some(Severity::Warning) | None => warning,
+ Some(Severity::Info) => info,
+ Some(Severity::Hint) => hint,
}
- }
- None
+ })
},
)
}