Revert "Fix language servers improper restarts"

This reverts commit 91832c8cd8.
This commit is contained in:
Kirill Bulatov 2023-07-11 20:46:45 +03:00
parent 8161438a85
commit efe8b8b6d0
2 changed files with 13 additions and 32 deletions

View file

@ -90,8 +90,7 @@ pub struct LanguageServerName(pub Arc<str>);
/// once at startup, and caches the results.
pub struct CachedLspAdapter {
pub name: LanguageServerName,
initialization_options: Option<Value>,
initialization_overrides: Mutex<Option<Value>>,
pub initialization_options: Option<Value>,
pub disk_based_diagnostic_sources: Vec<String>,
pub disk_based_diagnostics_progress_token: Option<String>,
pub language_ids: HashMap<String, String>,
@ -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<CodeLabel> {
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<Value> {
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 {

View file

@ -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::<ProjectSettings>(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();