diff --git a/crates/ide-lsp/src/handler.rs b/crates/ide-lsp/src/handler.rs index 17646993a..5fbb0d2df 100644 --- a/crates/ide-lsp/src/handler.rs +++ b/crates/ide-lsp/src/handler.rs @@ -563,10 +563,15 @@ impl ClientHandler { // vtsls asks for the whole configuration as section `""`. .map(|item| match item.get("section").and_then(Value::as_str).filter(|s| !s.is_empty()) { // The server's own section: its block under `settings` (basedpyright asks - // `basedpyright` and `basedpyright.analysis`), else the options themselves. - Some(section) if section == self.server.name => { - options.get("settings").and_then(|s| s.get(section)).unwrap_or(&options).clone() - } + // `basedpyright` and `basedpyright.analysis`), or the block of the same + // name at the top (the wrapped form the editor saves: + // `{"intelephense": {...}}`), else the options themselves (#7609). + Some(section) if section == self.server.name => options + .get("settings") + .and_then(|s| s.get(section)) + .or_else(|| options.get(section)) + .unwrap_or(&options) + .clone(), // Servers that take settings under `initializationOptions.settings` // (jdtls) ask for the same sections later. Some(section) => [&options, options.get("settings").unwrap_or(&Value::Null)] diff --git a/crates/ide-lsp/tests/mock_server.rs b/crates/ide-lsp/tests/mock_server.rs index bdef863bd..051211719 100644 --- a/crates/ide-lsp/tests/mock_server.rs +++ b/crates/ide-lsp/tests/mock_server.rs @@ -3013,6 +3013,34 @@ async fn eslint_configuration_includes_workspace_folder() { assert_eq!(other, json!([{ "flag": true, "nested": { "deep": 1 } }])); } +/// The server's own section is answered with its own settings block, not with the whole +/// configuration wrapped again: Intelephense asks `intelephense` and reads `files` and +/// `environment` off the answer, and the Workspace Configuration editor saves the +/// settings under the server's name (`{"intelephense": {...}}`) (#7609). +#[tokio::test(flavor = "multi_thread")] +async fn the_server_s_own_section_is_answered_with_its_own_block() { + let h = harness_configured("mock", "mk", &[("mock", incremental_caps())], |cfg| { + cfg.settings = Some(json!({ "mock": { "files": { "maxSize": 5000000, "exclude": ["**/var/**"] } } })); + }); + h.open("a.mk", "x"); + h.wait_status("mock", ServerStatus::Ready).await; + let state = h.launcher.state("mock"); + let items = json!({ "items": [{ "section": "mock" }, { "section": "mock.files" }, { "section": "" }] }); + let answer: Value = state.peer().request("workspace/configuration", items, None).await.unwrap(); + assert_eq!(answer[0], json!({ "files": { "maxSize": 5000000, "exclude": ["**/var/**"] } })); + // A dotted sub-section is looked up inside the wrapped block. + assert_eq!(answer[1], json!({ "maxSize": 5000000, "exclude": ["**/var/**"] })); + // An empty section still names the whole configuration (merged with the defaults). + assert_eq!( + answer[2], + json!({ + "flag": true, + "mock": { "files": { "maxSize": 5000000, "exclude": ["**/var/**"] } }, + "nested": { "deep": 1 }, + }) + ); +} + #[tokio::test(flavor = "multi_thread")] async fn settings_changes_reach_servers_without_restarts() { let h = harness(&[("mock", incremental_caps()), ("extra", incremental_caps())]);