Skip to content

Commit e4ba07f

Browse files
committed
fix(language_server): always write to memory file system (#15975)
In #15882 we removed the dynamic formatting registration and registered them statically. LSP Clients could only support static formatting registration and the checks would fail. When someone formats, while not saving, the unsaved changes would disappear. Removed the checks, so it always saves the content in the file system. Later the Linter will use the file system too when supporting [textDocument/diagnostic](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_diagnostic)
1 parent 54e8799 commit e4ba07f

File tree

2 files changed

+8
-23
lines changed

2 files changed

+8
-23
lines changed

crates/oxc_language_server/src/backend.rs

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,8 @@ impl LanguageServer for Backend {
233233
{
234234
warn!("sending unregisterCapability.didChangeWatchedFiles failed: {err}");
235235
}
236+
self.file_system.write().await.clear();
236237

237-
if self.capabilities.get().is_some_and(|option| option.dynamic_formatting) {
238-
self.file_system.write().await.clear();
239-
}
240238
Ok(())
241239
}
242240

@@ -466,10 +464,8 @@ impl LanguageServer for Backend {
466464
return;
467465
};
468466

469-
if self.capabilities.get().is_some_and(|option| option.dynamic_formatting) {
470-
// saving the file means we can read again from the file system
471-
self.file_system.write().await.remove(uri);
472-
}
467+
// saving the file means we can read again from the file system
468+
self.file_system.write().await.remove(uri);
473469

474470
if let Some(diagnostics) = worker.run_diagnostic_on_save(uri, None).await {
475471
self.client.publish_diagnostics(uri.clone(), diagnostics, None).await;
@@ -487,9 +483,7 @@ impl LanguageServer for Backend {
487483
};
488484
let content = params.content_changes.first().map(|c| c.text.clone());
489485

490-
if self.capabilities.get().is_some_and(|option| option.dynamic_formatting)
491-
&& let Some(content) = &content
492-
{
486+
if let Some(content) = &content {
493487
self.file_system.write().await.set(uri, content.clone());
494488
}
495489

@@ -513,9 +507,7 @@ impl LanguageServer for Backend {
513507

514508
let content = params.text_document.text;
515509

516-
if self.capabilities.get().is_some_and(|option| option.dynamic_formatting) {
517-
self.file_system.write().await.set(uri, content.clone());
518-
}
510+
self.file_system.write().await.set(uri, content.clone());
519511

520512
if let Some(diagnostics) = worker.run_diagnostic(uri, Some(&content)).await {
521513
self.client
@@ -534,9 +526,8 @@ impl LanguageServer for Backend {
534526
let Some(worker) = workers.iter().find(|worker| worker.is_responsible_for_uri(uri)) else {
535527
return;
536528
};
537-
if self.capabilities.get().is_some_and(|option| option.dynamic_formatting) {
538-
self.file_system.write().await.remove(uri);
539-
}
529+
530+
self.file_system.write().await.remove(uri);
540531
worker.remove_diagnostics(&params.text_document.uri).await;
541532
}
542533

crates/oxc_language_server/src/capabilities.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ pub struct Capabilities {
99
pub workspace_apply_edit: bool,
1010
pub workspace_configuration: bool,
1111
pub dynamic_watchers: bool,
12-
pub dynamic_formatting: bool,
1312
}
1413

1514
impl From<ClientCapabilities> for Capabilities {
@@ -25,13 +24,8 @@ impl From<ClientCapabilities> for Capabilities {
2524
watched_files.dynamic_registration.is_some_and(|dynamic| dynamic)
2625
})
2726
});
28-
let dynamic_formatting = value.text_document.as_ref().is_some_and(|text_document| {
29-
text_document.formatting.is_some_and(|formatting| {
30-
formatting.dynamic_registration.is_some_and(|dynamic| dynamic)
31-
})
32-
});
3327

34-
Self { workspace_apply_edit, workspace_configuration, dynamic_watchers, dynamic_formatting }
28+
Self { workspace_apply_edit, workspace_configuration, dynamic_watchers }
3529
}
3630
}
3731

0 commit comments

Comments
 (0)