From 9855b9bf0b5f031def94633f1176a84bd7122bbd Mon Sep 17 00:00:00 2001 From: Pascal Kuthe Date: Sat, 27 Apr 2024 17:09:05 +0200 Subject: [PATCH] fix lsp restart --- helix-lsp/src/lib.rs | 50 +++++++++++++++++++------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 04f018bc423d..3e0b35884c0a 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -736,35 +736,29 @@ impl Registry { .language_servers .iter() .filter_map(|LanguageServerFeatures { name, .. }| { - if self.inner_by_name.contains_key(name) { - let client = match self.start_client( - name.clone(), - language_config, - doc_path, - root_dirs, - enable_snippets, - ) { - Ok(client) => client, - Err(StartupError::NoRequiredRootFound) => return None, - Err(StartupError::Error(err)) => return Some(Err(err)), - }; - let old_clients = self - .inner_by_name - .insert(name.clone(), vec![client.clone()]) - .unwrap(); - - for old_client in old_clients { - self.file_event_handler.remove_client(old_client.id()); - self.inner.remove(client.id()); - tokio::spawn(async move { - let _ = old_client.force_shutdown().await; - }); - } - - Some(Ok(client)) - } else { - None + let old_clients = self.inner_by_name.remove(name)?; + for old_client in old_clients { + self.file_event_handler.remove_client(old_client.id()); + self.inner.remove(old_client.id()); + tokio::spawn(async move { + let _ = old_client.force_shutdown().await; + }); } + let client = match self.start_client( + name.clone(), + language_config, + doc_path, + root_dirs, + enable_snippets, + ) { + Ok(client) => client, + Err(StartupError::NoRequiredRootFound) => return None, + Err(StartupError::Error(err)) => return Some(Err(err)), + }; + self.inner_by_name + .insert(name.to_owned(), vec![client.clone()]); + + Some(Ok(client)) }) .collect() }