Skip to content

Commit a2bf52e

Browse files
autofix-ci[bot]Sysix
authored andcommitted
[autofix.ci] apply automated fixes
1 parent 13f835c commit a2bf52e

File tree

6 files changed

+9
-8
lines changed

6 files changed

+9
-8
lines changed

Cargo.lock

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

crates/oxc_language_server/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ oxc_diagnostics = { workspace = true }
2727
oxc_formatter = { workspace = true }
2828
oxc_linter = { workspace = true, features = ["language_server"] }
2929
oxc_parser = { workspace = true }
30-
oxc_span = { workspace = true }
3130

3231
#
3332
env_logger = { workspace = true, features = ["humantime"] }

crates/oxc_language_server/src/file_system.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ impl LSPFileSystem {
2121
self.files.pin().insert(uri.clone(), content);
2222
}
2323

24-
#[expect(dead_code)] // used for the oxc_formatter in the future
2524
pub fn get(&self, uri: &Uri) -> Option<String> {
2625
self.files.pin().get(uri).cloned()
2726
}

crates/oxc_language_server/src/formatter/server_formatter.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,14 @@ impl ServerFormatter {
1616
}
1717

1818
#[expect(clippy::unused_self)]
19-
pub fn run_single(&self, uri: &Uri) -> Option<Vec<TextEdit>> {
19+
pub fn run_single(&self, uri: &Uri, content: Option<String>) -> Option<Vec<TextEdit>> {
2020
let path = uri.to_file_path()?;
2121
let source_type = get_supported_source_type(&path)?;
22-
let source_text = std::fs::read_to_string(path).expect("Failed to read file");
22+
let source_text = if let Some(content) = content {
23+
content
24+
} else {
25+
std::fs::read_to_string(&path).ok()?
26+
};
2327

2428
let allocator = Allocator::new();
2529
let ret = Parser::new(&allocator, &source_text, source_type)

crates/oxc_language_server/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ impl LanguageServer for Backend {
593593
let Some(worker) = workers.iter().find(|worker| worker.is_responsible_for_uri(uri)) else {
594594
return Ok(None);
595595
};
596-
Ok(worker.format_file(uri).await)
596+
Ok(worker.format_file(uri, self.file_system.read().await.get(uri)).await)
597597
}
598598
}
599599

crates/oxc_language_server/src/worker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ impl WorkspaceWorker {
156156
server_linter.run_single(uri, content, run_type).await
157157
}
158158

159-
pub async fn format_file(&self, uri: &Uri) -> Option<Vec<TextEdit>> {
159+
pub async fn format_file(&self, uri: &Uri, content: Option<String>) -> Option<Vec<TextEdit>> {
160160
let Some(server_formatter) = &*self.server_formatter.read().await else {
161161
return None;
162162
};
163163

164-
server_formatter.run_single(uri)
164+
server_formatter.run_single(uri, content)
165165
}
166166

167167
async fn revalidate_diagnostics(

0 commit comments

Comments
 (0)