Skip to content

Commit d5b416e

Browse files
fix(lsp): make update_workspace_folders perform incremental updates per LSP spec (#7789)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent ee2f5bf commit d5b416e

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

.changeset/fair-crabs-play.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 the LSP method `workspace/didChangeWorkspaceFolders` to perform incremental updates instead of replacing the entire folder list.

crates/biome_lsp/src/server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,8 @@ impl LanguageServer for LSPServer {
408408
}
409409
}
410410

411-
self.session.update_workspace_folders(params.event.added);
411+
self.session
412+
.update_workspace_folders(params.event.added, params.event.removed);
412413
self.session.load_workspace_settings(true).await;
413414
}
414415

crates/biome_lsp/src/session.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,24 @@ impl Session {
587587
self.workspace_folders.read().unwrap().clone()
588588
}
589589

590-
pub(crate) fn update_workspace_folders(&self, folders: Vec<WorkspaceFolder>) {
590+
pub(crate) fn update_workspace_folders(
591+
&self,
592+
added: Vec<WorkspaceFolder>,
593+
removed: Vec<WorkspaceFolder>,
594+
) {
591595
let mut workspace_folders = self.workspace_folders.write().unwrap();
592-
*workspace_folders = Some(folders);
596+
597+
if let Some(ref mut folders) = *workspace_folders {
598+
if !removed.is_empty() {
599+
folders.retain(|folder| !removed.contains(folder));
600+
}
601+
602+
if !added.is_empty() {
603+
folders.extend(added);
604+
}
605+
} else {
606+
*workspace_folders = Some(added);
607+
}
593608
}
594609

595610
/// Returns the base path of the workspace on the filesystem if it has one

0 commit comments

Comments
 (0)