use tinymist_world::{
mock::{MockCompilerFeat, MockWorldBuilder},
vfs::{mock::MockChange, notify::NotifyMessage},
};
use tokio::sync::mpsc;
use crate::{CompileServerOpts, Interrupt, ProjectCompiler};
pub type MockProjectCompiler<Ext = ()> = ProjectCompiler<MockCompilerFeat, Ext>;
pub trait MockProjectBuilderExt {
fn project_compiler<Ext>(
&self,
) -> typst::diag::FileResult<(
MockProjectCompiler<Ext>,
mpsc::UnboundedReceiver<NotifyMessage>,
)>
where
Ext: Default + 'static;
fn project_compiler_with_opts<Ext>(
&self,
opts: CompileServerOpts<MockCompilerFeat, Ext>,
) -> typst::diag::FileResult<(
MockProjectCompiler<Ext>,
mpsc::UnboundedReceiver<NotifyMessage>,
)>
where
Ext: Default + 'static;
}
impl MockProjectBuilderExt for MockWorldBuilder {
fn project_compiler<Ext>(
&self,
) -> typst::diag::FileResult<(
MockProjectCompiler<Ext>,
mpsc::UnboundedReceiver<NotifyMessage>,
)>
where
Ext: Default + 'static,
{
self.project_compiler_with_opts(CompileServerOpts {
syntax_only: true,
..Default::default()
})
}
fn project_compiler_with_opts<Ext>(
&self,
opts: CompileServerOpts<MockCompilerFeat, Ext>,
) -> typst::diag::FileResult<(
MockProjectCompiler<Ext>,
mpsc::UnboundedReceiver<NotifyMessage>,
)>
where
Ext: Default + 'static,
{
let (tx, rx) = mpsc::unbounded_channel();
Ok((ProjectCompiler::new(self.build_universe()?, tx, opts), rx))
}
}
pub trait MockProjectChangeExt {
fn apply_as_fs_to_project<F, Ext>(&self, compiler: &mut ProjectCompiler<F, Ext>, is_sync: bool)
where
F: tinymist_world::CompilerFeat + Send + Sync + 'static,
Ext: Default + 'static;
fn apply_as_memory_to_project<F, Ext>(&self, compiler: &mut ProjectCompiler<F, Ext>)
where
F: tinymist_world::CompilerFeat + Send + Sync + 'static,
Ext: Default + 'static;
}
impl MockProjectChangeExt for MockChange {
fn apply_as_fs_to_project<F, Ext>(&self, compiler: &mut ProjectCompiler<F, Ext>, is_sync: bool)
where
F: tinymist_world::CompilerFeat + Send + Sync + 'static,
Ext: Default + 'static,
{
compiler.process(Interrupt::Fs(self.filesystem_event(is_sync)));
}
fn apply_as_memory_to_project<F, Ext>(&self, compiler: &mut ProjectCompiler<F, Ext>)
where
F: tinymist_world::CompilerFeat + Send + Sync + 'static,
Ext: Default + 'static,
{
compiler.process(Interrupt::Memory(self.memory_event()));
}
}