diff options
author | Blaž Hrastnik | 2023-05-19 00:39:35 +0000 |
---|---|---|
committer | GitHub | 2023-05-19 00:39:35 +0000 |
commit | 53f47bc47771c94dab51626ca025be28e62eba0c (patch) | |
tree | c8f5c59d40d1ecde227c209f898cc7afd6da5477 /helix-view/src/gutter.rs | |
parent | 7f5940be80eaa3aec7903903072b7108f41dd97b (diff) | |
parent | 2a512f7c487f0a707a7eb158e24bd478433bcd91 (diff) |
Merge pull request #2507 from Philipp-M/multiple-language-servers
Add support for multiple language servers per language
Diffstat (limited to 'helix-view/src/gutter.rs')
-rw-r--r-- | helix-view/src/gutter.rs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/helix-view/src/gutter.rs b/helix-view/src/gutter.rs index 3ecae919..a332a8a3 100644 --- a/helix-view/src/gutter.rs +++ b/helix-view/src/gutter.rs @@ -1,5 +1,7 @@ use std::fmt::Write; +use helix_core::syntax::LanguageServerFeature; + use crate::{ editor::GutterType, graphics::{Style, UnderlineStyle}, @@ -55,7 +57,7 @@ pub fn diagnostic<'doc>( let error = theme.get("error"); let info = theme.get("info"); let hint = theme.get("hint"); - let diagnostics = doc.diagnostics(); + let diagnostics = &doc.diagnostics; Box::new( move |line: usize, _selected: bool, first_visual_line: bool, out: &mut String| { @@ -63,28 +65,24 @@ 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 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 { + let first_diag_idx_maybe_on_line = diagnostics.partition_point(|d| d.line < line); + 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) + }); + 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 + } + }) }, ) } |