mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-04 02:08:17 +00:00
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:
parent
497a1e0aea
commit
1cf20585f4
4 changed files with 23 additions and 17 deletions
|
@ -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)))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue