Simplify gutter diagnostics rendering by using partition_point instead of binary search
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
This commit is contained in:
parent
2b746ea6fa
commit
656ee24966
1 changed files with 17 additions and 25 deletions
|
@ -1,6 +1,6 @@
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
use helix_core::{syntax::LanguageServerFeature, Diagnostic};
|
use helix_core::syntax::LanguageServerFeature;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
editor::GutterType,
|
editor::GutterType,
|
||||||
|
@ -65,35 +65,27 @@ pub fn diagnostic<'doc>(
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
use helix_core::diagnostic::Severity;
|
use helix_core::diagnostic::Severity;
|
||||||
if let Ok(index) = diagnostics.binary_search_by_key(&line, |d| d.line) {
|
let first_diag_idx_maybe_on_line = diagnostics.partition_point(|d| d.line < line);
|
||||||
let on_line_and_is_visible = |d: &&Diagnostic| {
|
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
|
d.line == line
|
||||||
&& doc
|
&& doc
|
||||||
.language_servers_with_feature(LanguageServerFeature::Diagnostics)
|
.language_servers_with_feature(LanguageServerFeature::Diagnostics)
|
||||||
.any(|ls| ls.id() == d.language_server_id)
|
.any(|ls| ls.id() == d.language_server_id)
|
||||||
};
|
});
|
||||||
let after = diagnostics[index..]
|
diagnostics_on_line.max_by_key(|d| d.severity).map(|d| {
|
||||||
.iter()
|
write!(out, "●").ok();
|
||||||
.take_while(on_line_and_is_visible);
|
match d.severity {
|
||||||
|
Some(Severity::Error) => error,
|
||||||
let before = diagnostics[..index]
|
Some(Severity::Warning) | None => warning,
|
||||||
.iter()
|
Some(Severity::Info) => info,
|
||||||
.rev()
|
Some(Severity::Hint) => hint,
|
||||||
.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,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
None
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue