mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 15:24:46 -05:00
perf(lsp): format in a blocking task (#19883)
This commit is contained in:
parent
0c3bbf7acd
commit
1ee6218e48
1 changed files with 26 additions and 17 deletions
|
@ -1638,9 +1638,14 @@ impl Inner {
|
||||||
return Ok(None);
|
return Ok(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let format_result = match document.maybe_parsed_source() {
|
// spawn a blocking task to allow doing other work while this is occurring
|
||||||
|
let format_result = deno_core::task::spawn_blocking({
|
||||||
|
let fmt_options = self.fmt_options.options.clone();
|
||||||
|
let document = document.clone();
|
||||||
|
move || {
|
||||||
|
match document.maybe_parsed_source() {
|
||||||
Some(Ok(parsed_source)) => {
|
Some(Ok(parsed_source)) => {
|
||||||
format_parsed_source(&parsed_source, &self.fmt_options.options)
|
format_parsed_source(&parsed_source, &fmt_options)
|
||||||
}
|
}
|
||||||
Some(Err(err)) => Err(anyhow!("{}", err)),
|
Some(Err(err)) => Err(anyhow!("{}", err)),
|
||||||
None => {
|
None => {
|
||||||
|
@ -1653,9 +1658,13 @@ impl Inner {
|
||||||
.map(|ext| file_path.with_extension(ext))
|
.map(|ext| file_path.with_extension(ext))
|
||||||
.unwrap_or(file_path);
|
.unwrap_or(file_path);
|
||||||
// it's not a js/ts file, so attempt to format its contents
|
// it's not a js/ts file, so attempt to format its contents
|
||||||
format_file(&file_path, &document.content(), &self.fmt_options.options)
|
format_file(&file_path, &document.content(), &fmt_options)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let text_edits = match format_result {
|
let text_edits = match format_result {
|
||||||
Ok(Some(new_text)) => Some(text::get_edits(
|
Ok(Some(new_text)) => Some(text::get_edits(
|
||||||
|
|
Loading…
Reference in a new issue