use std::sync::atomic::{AtomicBool, Ordering};
use typst::{
Document, World,
diag::{SourceDiagnostic, SourceResult, Warned},
ecow::eco_vec,
};
use typst_syntax::Span;
pub static SYNTAX_ONLY: AtomicBool = AtomicBool::new(false);
pub fn is_syntax_only() -> bool {
SYNTAX_ONLY.load(Ordering::Acquire)
}
pub fn compile_opt<D>(world: &dyn World) -> Warned<SourceResult<D>>
where
D: Document,
{
if is_syntax_only() {
Warned {
output: Err(eco_vec![SourceDiagnostic::error(
Span::detached(),
"Compilation is disabled in syntax-only mode.",
)]),
warnings: Default::default(),
}
} else {
typst::compile::<D>(world)
}
}