From 757f05042d2b1339703664c6fe4343daf4fd333b Mon Sep 17 00:00:00 2001 From: Julia Date: Thu, 16 Mar 2023 17:19:17 -0400 Subject: [PATCH] Fix deadlock while initializing JSON language server As it turns out both parking-lot and std's `RwLock` disallows taking multiple read locks on the same thread Co-Authored-By: Max Brunsfeld --- crates/language/src/language.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index 84311f9d79..ed02b8de59 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -567,20 +567,25 @@ impl LanguageRegistry { } pub fn workspace_configuration(&self, cx: &mut MutableAppContext) -> Task { - let state = self.state.read(); + let lsp_adapters = { + let state = self.state.read(); + state + .available_languages + .iter() + .filter_map(|l| l.lsp_adapter.clone()) + .chain( + state + .languages + .iter() + .filter_map(|l| l.adapter.as_ref().map(|a| a.adapter.clone())), + ) + .collect::>() + }; + let mut language_configs = Vec::new(); - for language in &state.available_languages { - if let Some(adapter) = language.lsp_adapter.as_ref() { - if let Some(language_config) = adapter.workspace_configuration(cx) { - language_configs.push(language_config); - } - } - } - for language in &state.languages { - if let Some(adapter) = language.lsp_adapter() { - if let Some(language_config) = adapter.workspace_configuration(cx) { - language_configs.push(language_config); - } + for adapter in &lsp_adapters { + if let Some(language_config) = adapter.workspace_configuration(cx) { + language_configs.push(language_config); } }