From 12f6ad32c2108efb1492df6192a1f8cdd5eafa76 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Sat, 2 Sep 2023 16:36:04 +0100 Subject: fix(lsp): properly handle disabled configuration requests (#20358) Fixes #19802. Properly respect when clients do not have the `workspace/configuration` capability, a.k.a. when an editor cannot provide scoped settings on request from the LSP. - Fix one spot where we weren't checking for the capability before sending this request. - For `enablePaths`, fall back to the settings passed in the initialization options in more cases. - Respect the `workspace/configuration` capability in the test harness client. See: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration. --- cli/lsp/config.rs | 13 ++++++------- cli/lsp/language_server.rs | 15 +++++++++------ 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'cli/lsp') diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index b70af6519..2d77abaee 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -718,13 +718,12 @@ impl Config { if let Some(workspace_folders) = self.workspace_folders.clone() { let mut touched = false; for (workspace, _) in workspace_folders { - if let Some(settings) = self.settings.specifiers.get(&workspace) { - if self.update_enabled_paths_entry( - workspace, - settings.enable_paths.clone(), - ) { - touched = true; - } + let enabled_paths = match self.settings.specifiers.get(&workspace) { + Some(settings) => settings.enable_paths.clone(), + None => self.settings.workspace.enable_paths.clone(), + }; + if self.update_enabled_paths_entry(workspace, enabled_paths) { + touched = true; } } touched diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index dc85eb1cc..d4e5b3da9 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -1275,6 +1275,7 @@ impl Inner { error!("Cannot set workspace settings: {}", err); LspError::internal_error() })?; + self.config.update_enabled_paths(); } self.config.workspace_folders = params.workspace_folders.map(|folders| { folders @@ -1471,6 +1472,7 @@ impl Inner { if let Err(err) = self.config.set_workspace_settings(value) { error!("failed to update settings: {}", err); } + self.config.update_enabled_paths(); } self.update_debug_flag(); @@ -3125,7 +3127,7 @@ impl tower_lsp::LanguageServer for LanguageServer { return; } - let (client, client_uri, specifier, had_specifier_settings) = { + let (client, client_uri, specifier, should_get_specifier_settings) = { let mut inner = self.0.write().await; let client = inner.client.clone(); let client_uri = LspClientUrl::new(params.text_document.uri.clone()); @@ -3133,24 +3135,25 @@ impl tower_lsp::LanguageServer for LanguageServer { .url_map .normalize_url(client_uri.as_url(), LspUrlKind::File); let document = inner.did_open(&specifier, params).await; - let has_specifier_settings = - inner.config.has_specifier_settings(&specifier); + let should_get_specifier_settings = + !inner.config.has_specifier_settings(&specifier) + && inner.config.client_capabilities.workspace_configuration; if document.is_diagnosable() { inner.refresh_npm_specifiers().await; let specifiers = inner.documents.dependents(&specifier); inner.diagnostics_server.invalidate(&specifiers); // don't send diagnostics yet if we don't have the specifier settings - if has_specifier_settings { + if !should_get_specifier_settings { inner.send_diagnostics_update(); inner.send_testing_update(); } } - (client, client_uri, specifier, has_specifier_settings) + (client, client_uri, specifier, should_get_specifier_settings) }; // retrieve the specifier settings outside the lock if // they haven't been asked for yet - if !had_specifier_settings { + if should_get_specifier_settings { let response = client .when_outside_lsp_lock() .specifier_configuration(&client_uri) -- cgit v1.2.3