From 080a085fa796fe2b71b5932b704d465695fba824 Mon Sep 17 00:00:00 2001 From: woojiq Date: Tue, 26 Sep 2023 23:12:19 +0300 Subject: Filter out language servers which fail to spawn (#8374) --- helix-lsp/src/lib.rs | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) (limited to 'helix-lsp/src') diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index d29a2144..a4be923b 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -749,36 +749,40 @@ impl Registry { } } - pub fn get( - &mut self, - language_config: &LanguageConfiguration, - doc_path: Option<&std::path::PathBuf>, - root_dirs: &[PathBuf], + pub fn get<'a>( + &'a mut self, + language_config: &'a LanguageConfiguration, + doc_path: Option<&'a std::path::PathBuf>, + root_dirs: &'a [PathBuf], enable_snippets: bool, - ) -> Result>> { - language_config - .language_servers - .iter() - .map(|LanguageServerFeatures { name, .. }| { + ) -> impl Iterator>)> + 'a { + language_config.language_servers.iter().map( + move |LanguageServerFeatures { name, .. }| { if let Some(clients) = self.inner.get(name) { if let Some((_, client)) = clients.iter().enumerate().find(|(i, client)| { client.try_add_doc(&language_config.roots, root_dirs, doc_path, *i == 0) }) { - return Ok((name.to_owned(), client.clone())); + return (name.to_owned(), Ok(client.clone())); } } - let client = self.start_client( + match self.start_client( name.clone(), language_config, doc_path, root_dirs, enable_snippets, - )?; - let clients = self.inner.entry(name.clone()).or_default(); - clients.push(client.clone()); - Ok((name.clone(), client)) - }) - .collect() + ) { + Ok(client) => { + self.inner + .entry(name.to_owned()) + .or_default() + .push(client.clone()); + (name.clone(), Ok(client)) + } + Err(err) => (name.to_owned(), Err(err)), + } + }, + ) } pub fn iter_clients(&self) -> impl Iterator> { -- cgit v1.2.3-70-g09d2