Skip to content

Commit cddaa44

Browse files
fix(lsp): handle wrapped settings in didChangeConfiguration (#9611)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent db67d22 commit cddaa44

4 files changed

Lines changed: 85 additions & 0 deletions

File tree

.changeset/three-candles-tan.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed a regression where Biome LSP could misread editor settings sent through `workspace/didChangeConfiguration` when the payload was wrapped in a top-level `biome` key. This caused `requireConfiguration` and related settings to be ignored in some editors.

crates/biome_configuration/src/generated/linter_options_check.rs

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/biome_lsp/src/server.tests.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4660,6 +4660,77 @@ async fn should_acknowledge_changes_in_settings_when_pulling_diagnostics() -> Re
46604660
Ok(())
46614661
}
46624662

4663+
#[tokio::test]
4664+
async fn should_apply_wrapped_biome_settings_from_did_change_configuration() -> Result<()> {
4665+
let factory = ServerFactory::default();
4666+
let (service, client) = factory.create().into_inner();
4667+
let (stream, sink) = client.split();
4668+
let mut server = Server::new(service);
4669+
4670+
let (sender, mut receiver) = channel(CHANNEL_BUFFER_SIZE);
4671+
let reader = tokio::spawn(client_handler(stream, sink, sender));
4672+
4673+
server.initialize().await?;
4674+
server.initialized().await?;
4675+
4676+
server
4677+
.open_document("import { b, a } from \"./foo\";\n")
4678+
.await?;
4679+
4680+
let notification = wait_for_notification(&mut receiver, |n| n.is_publish_diagnostics()).await;
4681+
4682+
assert!(notification.is_some());
4683+
4684+
let notification = notification.expect("notification");
4685+
assert!(matches!(
4686+
notification,
4687+
ServerNotification::PublishDiagnostics(_)
4688+
));
4689+
if let ServerNotification::PublishDiagnostics(result) = notification {
4690+
assert!(
4691+
!result.diagnostics.is_empty(),
4692+
"should contain diagnostics before applying wrapped biome settings"
4693+
);
4694+
}
4695+
4696+
sleep(Duration::from_millis(300)).await;
4697+
4698+
server
4699+
.notify(
4700+
"workspace/didChangeConfiguration",
4701+
DidChangeConfigurationParams {
4702+
settings: serde_json::json!({
4703+
"biome": {
4704+
"requireConfiguration": true,
4705+
"configurationPath": null,
4706+
}
4707+
}),
4708+
},
4709+
)
4710+
.await?;
4711+
4712+
let notification = wait_for_notification(&mut receiver, |n| n.is_publish_diagnostics()).await;
4713+
4714+
assert_eq!(
4715+
notification,
4716+
Some(ServerNotification::PublishDiagnostics(
4717+
PublishDiagnosticsParams {
4718+
uri: uri!("document.js"),
4719+
version: Some(0),
4720+
diagnostics: vec![],
4721+
}
4722+
)),
4723+
"diagnostics should be cleared after applying wrapped biome settings from didChangeConfiguration"
4724+
);
4725+
4726+
server.close_document().await?;
4727+
4728+
server.shutdown().await?;
4729+
reader.abort();
4730+
4731+
Ok(())
4732+
}
4733+
46634734
#[tokio::test]
46644735
async fn pull_plugin_diagnostics_for_vue_files() -> Result<()> {
46654736
let fs = MemoryFileSystem::default();

crates/biome_lsp/src/session.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,6 +1175,10 @@ impl Session {
11751175
}
11761176
}
11771177
Some(settings) => {
1178+
let settings = settings
1179+
.get(CONFIGURATION_SECTION)
1180+
.cloned()
1181+
.unwrap_or(settings);
11781182
let mut config = self.extension_settings.write().unwrap();
11791183
if let Err(err) = config.set_workspace_settings(settings) {
11801184
error!("Couldn't set client configuration: {}", err);

0 commit comments

Comments
 (0)