typst_shim/
syntax_only.rs1use std::sync::atomic::{AtomicBool, Ordering};
2use typst::{
3 World,
4 diag::{SourceDiagnostic, SourceResult, Warned},
5 ecow::eco_vec,
6 foundations::Output,
7};
8use typst_syntax::Span;
9
10pub static SYNTAX_ONLY: AtomicBool = AtomicBool::new(false);
12
13pub fn is_syntax_only() -> bool {
15 SYNTAX_ONLY.load(Ordering::Acquire)
16}
17
18pub fn compile_opt<D>(world: &dyn World) -> Warned<SourceResult<D>>
21where
22 D: Output,
23{
24 if is_syntax_only() {
25 Warned {
26 output: Err(eco_vec![SourceDiagnostic::error(
27 Span::detached(),
28 "Compilation is disabled in syntax-only mode.",
29 )]),
30 warnings: Default::default(),
31 }
32 } else {
33 typst::compile::<D>(world)
34 }
35}