1use tinymist_world::{
9 mock::{MockCompilerFeat, MockWorldBuilder},
10 vfs::{mock::MockChange, notify::NotifyMessage},
11};
12use tokio::sync::mpsc;
13
14use crate::{CompileServerOpts, Interrupt, ProjectCompiler};
15
16pub type MockProjectCompiler<Ext = ()> = ProjectCompiler<MockCompilerFeat, Ext>;
18
19pub trait MockProjectBuilderExt {
21 fn project_compiler<Ext>(
23 &self,
24 ) -> typst::diag::FileResult<(
25 MockProjectCompiler<Ext>,
26 mpsc::UnboundedReceiver<NotifyMessage>,
27 )>
28 where
29 Ext: Default + 'static;
30
31 fn project_compiler_with_opts<Ext>(
33 &self,
34 opts: CompileServerOpts<MockCompilerFeat, Ext>,
35 ) -> typst::diag::FileResult<(
36 MockProjectCompiler<Ext>,
37 mpsc::UnboundedReceiver<NotifyMessage>,
38 )>
39 where
40 Ext: Default + 'static;
41}
42
43impl MockProjectBuilderExt for MockWorldBuilder {
44 fn project_compiler<Ext>(
45 &self,
46 ) -> typst::diag::FileResult<(
47 MockProjectCompiler<Ext>,
48 mpsc::UnboundedReceiver<NotifyMessage>,
49 )>
50 where
51 Ext: Default + 'static,
52 {
53 self.project_compiler_with_opts(CompileServerOpts {
54 syntax_only: true,
55 ..Default::default()
56 })
57 }
58
59 fn project_compiler_with_opts<Ext>(
60 &self,
61 opts: CompileServerOpts<MockCompilerFeat, Ext>,
62 ) -> typst::diag::FileResult<(
63 MockProjectCompiler<Ext>,
64 mpsc::UnboundedReceiver<NotifyMessage>,
65 )>
66 where
67 Ext: Default + 'static,
68 {
69 let (tx, rx) = mpsc::unbounded_channel();
70 Ok((ProjectCompiler::new(self.build_universe()?, tx, opts), rx))
71 }
72}
73
74pub trait MockProjectChangeExt {
76 fn apply_as_fs_to_project<F, Ext>(&self, compiler: &mut ProjectCompiler<F, Ext>, is_sync: bool)
78 where
79 F: tinymist_world::CompilerFeat + Send + Sync + 'static,
80 Ext: Default + 'static;
81
82 fn apply_as_memory_to_project<F, Ext>(&self, compiler: &mut ProjectCompiler<F, Ext>)
84 where
85 F: tinymist_world::CompilerFeat + Send + Sync + 'static,
86 Ext: Default + 'static;
87}
88
89impl MockProjectChangeExt for MockChange {
90 fn apply_as_fs_to_project<F, Ext>(&self, compiler: &mut ProjectCompiler<F, Ext>, is_sync: bool)
91 where
92 F: tinymist_world::CompilerFeat + Send + Sync + 'static,
93 Ext: Default + 'static,
94 {
95 compiler.process(Interrupt::Fs(self.filesystem_event(is_sync)));
96 }
97
98 fn apply_as_memory_to_project<F, Ext>(&self, compiler: &mut ProjectCompiler<F, Ext>)
99 where
100 F: tinymist_world::CompilerFeat + Send + Sync + 'static,
101 Ext: Default + 'static,
102 {
103 compiler.process(Interrupt::Memory(self.memory_event()));
104 }
105}