diff options
author | Philipp Mildenberger | 2023-03-18 19:12:20 +0000 |
---|---|---|
committer | Philipp Mildenberger | 2023-05-18 19:48:32 +0000 |
commit | 76b5cab52479daf25ffa0af798c1ebcf6a4f0004 (patch) | |
tree | af2dc03114a05cb458518006ef16c3a74a28b097 /helix-view | |
parent | 0637691eb1fb7e2055fc04a0209be94906c2bd1a (diff) |
Refactored doc.language_servers and doc.language_servers_with_feature to return an iterator and refactor LanguageServerFeature handling to a HashMap (language server name maps to features)
Co-authored-by: Pascal Kuthe <pascal.kuthe@semimod.de>
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/document.rs | 52 | ||||
-rw-r--r-- | helix-view/src/editor.rs | 5 |
2 files changed, 13 insertions, 44 deletions
diff --git a/helix-view/src/document.rs b/helix-view/src/document.rs index 37ddc2b6..4b075293 100644 --- a/helix-view/src/document.rs +++ b/helix-view/src/document.rs @@ -6,7 +6,7 @@ use futures_util::FutureExt; use helix_core::auto_pairs::AutoPairs; use helix_core::doc_formatter::TextFormat; use helix_core::encoding::Encoding; -use helix_core::syntax::{Highlight, LanguageServerFeature, LanguageServerFeatureConfiguration}; +use helix_core::syntax::{Highlight, LanguageServerFeature}; use helix_core::text_annotations::{InlineAnnotation, TextAnnotations}; use helix_core::Range; use helix_vcs::{DiffHandle, DiffProviderRegistry}; @@ -734,7 +734,6 @@ impl Document { // finds first language server that supports formatting and then formats let (offset_encoding, request) = self .language_servers_with_feature(LanguageServerFeature::Format) - .iter() .find_map(|language_server| { let offset_encoding = language_server.offset_encoding(); let request = language_server.text_document_formatting( @@ -1437,54 +1436,24 @@ impl Document { self.version } - /// Language servers that have been initialized. - pub fn language_servers(&self) -> Vec<&helix_lsp::Client> { + pub fn language_servers(&self) -> impl Iterator<Item = &helix_lsp::Client> { self.language_servers .iter() .filter_map(|l| if l.is_initialized() { Some(&**l) } else { None }) - .collect() } // TODO filter also based on LSP capabilities? pub fn language_servers_with_feature( &self, feature: LanguageServerFeature, - ) -> Vec<&helix_lsp::Client> { - let language_servers = self.language_servers(); - - let language_config = match self.language_config() { - Some(language_config) => language_config, - None => return Vec::new(), - }; - - // O(n^2) but since language_servers will be of very small length, - // I don't see the necessity to optimize - language_config - .language_servers - .iter() - .filter_map(|c| match c { - LanguageServerFeatureConfiguration::Simple(name) => language_servers - .iter() - .find(|ls| ls.name() == name) - .copied(), - LanguageServerFeatureConfiguration::Features { - only_features, - except_features, - name, - } => { - if (only_features.is_empty() || only_features.contains(&feature)) - && !except_features.contains(&feature) - { - language_servers - .iter() - .find(|ls| ls.name() == name) - .copied() - } else { - None - } - } - }) - .collect() + ) -> impl Iterator<Item = &helix_lsp::Client> { + self.language_servers().filter(move |server| { + self.language_config() + .and_then(|config| config.language_servers.get(server.name())) + .map_or(false, |server_features| { + server_features.has_feature(feature) + }) + }) } pub fn diff_handle(&self) -> Option<&DiffHandle> { @@ -1610,7 +1579,6 @@ impl Document { pub fn shown_diagnostics(&self) -> impl Iterator<Item = &Diagnostic> + DoubleEndedIterator { let ls_ids: HashSet<_> = self .language_servers_with_feature(LanguageServerFeature::Diagnostics) - .iter() .map(|ls| ls.id()) .collect(); self.diagnostics diff --git a/helix-view/src/editor.rs b/helix-view/src/editor.rs index 366cc01c..bca97815 100644 --- a/helix-view/src/editor.rs +++ b/helix-view/src/editor.rs @@ -689,7 +689,7 @@ pub struct WhitespaceCharacters { impl Default for WhitespaceCharacters { fn default() -> Self { Self { - space: '·', // U+00B7 + space: '·', // U+00B7 nbsp: '⍽', // U+237D tab: '→', // U+2192 newline: '⏎', // U+23CE @@ -1129,7 +1129,8 @@ impl Editor { if let Some(language_servers) = language_servers { // only spawn new lang servers if the servers aren't the same - let doc_language_servers = doc.language_servers(); + // TODO simplify? + let doc_language_servers = doc.language_servers().collect::<Vec<_>>(); let spawn_new_servers = language_servers.len() != doc_language_servers.len() || language_servers .iter() |