build: bump typstyle to v0.12.13 (#1047)

* chore: bump typstyle to v0.12.13

* dev: code style

* dev: code style cont

---------

Co-authored-by: Myriad-Dreamin <camiyoru@gmail.com>
This commit is contained in:
Wenzhuo Liu 2024-12-22 15:11:00 +08:00 committed by GitHub
parent 497a1e0aea
commit 1cf20585f4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 23 additions and 17 deletions

View file

@ -6,6 +6,7 @@ use lsp_types::TextEdit;
use sync_lsp::{just_future, SchedulableResponse};
use tinymist_query::{to_lsp_range, PositionEncoding};
use typst::syntax::Source;
use typstyle_core::PrinterConfig;
use super::SyncTaskFactory;
use crate::FormatterMode;
@ -36,22 +37,24 @@ impl FormatTask {
pub fn run(&self, src: Source) -> SchedulableResponse<Option<Vec<TextEdit>>> {
let c = self.factory.task();
just_future(async move {
match c.mode {
FormatterMode::Typstyle => {
let cw = c.width as usize;
let res = typstyle_core::Typstyle::new_with_src(src.clone(), cw).pretty_print();
Ok(calc_diff(src, res, c.position_encoding))
}
FormatterMode::Typstfmt => {
let config = typstfmt_lib::Config {
let formatted = match c.mode {
FormatterMode::Typstyle => typstyle_core::Typstyle::new_with_src(
src.clone(),
PrinterConfig::new_with_width(c.width as usize),
)
.pretty_print()
.ok(),
FormatterMode::Typstfmt => Some(typstfmt_lib::format(
src.text(),
typstfmt_lib::Config {
max_line_length: c.width as usize,
..typstfmt_lib::Config::default()
};
let res = typstfmt_lib::format(src.text(), config);
Ok(calc_diff(src, res, c.position_encoding))
}
FormatterMode::Disable => Ok(None),
}
},
)),
FormatterMode::Disable => None,
};
Ok(formatted.and_then(|formatted| calc_diff(src, formatted, c.position_encoding)))
})
}
}