diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index 642f5469cd..976d8062ea 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -90,8 +90,7 @@ pub struct LanguageServerName(pub Arc); /// once at startup, and caches the results. pub struct CachedLspAdapter { pub name: LanguageServerName, - initialization_options: Option, - initialization_overrides: Mutex>, + pub initialization_options: Option, pub disk_based_diagnostic_sources: Vec, pub disk_based_diagnostics_progress_token: Option, pub language_ids: HashMap, @@ -110,7 +109,6 @@ impl CachedLspAdapter { Arc::new(CachedLspAdapter { name, initialization_options, - initialization_overrides: Mutex::new(None), disk_based_diagnostic_sources, disk_based_diagnostics_progress_token, language_ids, @@ -210,30 +208,6 @@ impl CachedLspAdapter { ) -> Option { self.adapter.label_for_symbol(name, kind, language).await } - - pub fn update_initialization_overrides(&self, new: Option<&Value>) -> bool { - let mut current = self.initialization_overrides.lock(); - if current.as_ref() != new { - *current = new.cloned(); - true - } else { - false - } - } - - pub fn initialization_options(&self) -> Option { - let initialization_options = self.initialization_options.as_ref(); - let override_options = self.initialization_overrides.lock().clone(); - match (initialization_options, override_options) { - (None, override_options) => override_options, - (initialization_options, None) => initialization_options.cloned(), - (Some(initialization_options), Some(override_options)) => { - let mut initialization_options = initialization_options.clone(); - merge_json_value_into(override_options, &mut initialization_options); - Some(initialization_options) - } - } - } } pub trait LspAdapterDelegate: Send + Sync { diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index dc4c8852dd..81db0c7ed7 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -78,8 +78,8 @@ use std::{ use terminals::Terminals; use text::Anchor; use util::{ - debug_panic, defer, http::HttpClient, paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, - TryFutureExt as _, + debug_panic, defer, http::HttpClient, merge_json_value_into, + paths::LOCAL_SETTINGS_RELATIVE_PATH, post_inc, ResultExt, TryFutureExt as _, }; pub use fs::*; @@ -800,7 +800,7 @@ impl Project { .lsp .get(&adapter.name.0) .and_then(|s| s.initialization_options.as_ref()); - if adapter.update_initialization_overrides(new_lsp_settings) { + if adapter.initialization_options.as_ref() != new_lsp_settings { language_servers_to_restart.push((worktree, Arc::clone(language))); } } @@ -2545,13 +2545,20 @@ impl Project { let project_settings = settings::get::(cx); let lsp = project_settings.lsp.get(&adapter.name.0); let override_options = lsp.map(|s| s.initialization_options.clone()).flatten(); - adapter.update_initialization_overrides(override_options.as_ref()); + + let mut initialization_options = adapter.initialization_options.clone(); + match (&mut initialization_options, override_options) { + (Some(initialization_options), Some(override_options)) => { + merge_json_value_into(override_options, initialization_options); + } + (None, override_options) => initialization_options = override_options, + _ => {} + } let server_id = pending_server.server_id; let container_dir = pending_server.container_dir.clone(); let state = LanguageServerState::Starting({ let adapter = adapter.clone(); - let initialization_options = adapter.initialization_options(); let server_name = adapter.name.0.clone(); let languages = self.languages.clone(); let language = language.clone();