1#![allow(missing_docs)]
4
5pub mod args;
6pub mod config;
7pub mod debug_loc;
8pub mod entry;
9pub mod font;
10pub mod package;
11pub mod parser;
12pub mod source;
13pub mod world;
14
15pub use compute::*;
16pub use entry::*;
17pub use snapshot::*;
18pub use world::*;
19
20pub use tinymist_vfs as vfs;
21
22mod compute;
23mod snapshot;
24
25#[cfg(feature = "system")]
27pub mod system;
28#[cfg(feature = "system")]
29pub use system::{print_diagnostics, SystemCompilerFeat, TypstSystemUniverse, TypstSystemWorld};
30
31#[cfg(feature = "browser")]
33pub(crate) mod browser;
34#[cfg(feature = "browser")]
35pub use browser::{BrowserCompilerFeat, TypstBrowserUniverse, TypstBrowserWorld};
36
37use std::{path::Path, sync::Arc};
38
39use ecow::EcoVec;
40use tinymist_vfs::PathAccessModel as VfsAccessModel;
41use typst::diag::{At, FileResult, SourceResult};
42use typst::foundations::Bytes;
43use typst::syntax::{FileId, Span};
44
45use font::FontResolver;
46use package::PackageRegistry;
47
48pub trait ShadowApi {
50 fn shadow_paths(&self) -> Vec<Arc<Path>>;
52 fn shadow_ids(&self) -> Vec<FileId>;
54
55 fn reset_shadow(&mut self) {
57 for path in self.shadow_paths() {
58 self.unmap_shadow(&path).unwrap();
59 }
60 }
61
62 fn map_shadow(&mut self, path: &Path, content: Bytes) -> FileResult<()>;
64
65 fn unmap_shadow(&mut self, path: &Path) -> FileResult<()>;
67
68 fn map_shadow_by_id(&mut self, file_id: FileId, content: Bytes) -> FileResult<()>;
72
73 fn unmap_shadow_by_id(&mut self, file_id: FileId) -> FileResult<()>;
77}
78
79pub trait ShadowApiExt {
80 fn with_shadow_file<T>(
82 &mut self,
83 file_path: &Path,
84 content: Bytes,
85 f: impl FnOnce(&mut Self) -> SourceResult<T>,
86 ) -> SourceResult<T>;
87
88 fn with_shadow_file_by_id<T>(
93 &mut self,
94 file_id: FileId,
95 content: Bytes,
96 f: impl FnOnce(&mut Self) -> SourceResult<T>,
97 ) -> SourceResult<T>;
98}
99
100impl<C: ShadowApi> ShadowApiExt for C {
101 fn with_shadow_file<T>(
103 &mut self,
104 file_path: &Path,
105 content: Bytes,
106 f: impl FnOnce(&mut Self) -> SourceResult<T>,
107 ) -> SourceResult<T> {
108 self.map_shadow(file_path, content).at(Span::detached())?;
109 let res: Result<T, EcoVec<typst::diag::SourceDiagnostic>> = f(self);
110 self.unmap_shadow(file_path).at(Span::detached())?;
111 res
112 }
113
114 fn with_shadow_file_by_id<T>(
119 &mut self,
120 file_id: FileId,
121 content: Bytes,
122 f: impl FnOnce(&mut Self) -> SourceResult<T>,
123 ) -> SourceResult<T> {
124 self.map_shadow_by_id(file_id, content)
125 .at(Span::detached())?;
126 let res: Result<T, EcoVec<typst::diag::SourceDiagnostic>> = f(self);
127 self.unmap_shadow_by_id(file_id).at(Span::detached())?;
128 res
129 }
130}
131
132pub trait WorldDeps {
134 fn iter_dependencies(&self, f: &mut dyn FnMut(FileId));
135}
136
137pub trait CompilerFeat: Send + Sync + 'static {
139 type FontResolver: FontResolver + Send + Sync + Sized;
141 type AccessModel: VfsAccessModel + Clone + Send + Sync + Sized;
143 type Registry: PackageRegistry + Send + Sync + Sized;
145}
146
147#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd)]
149pub enum DiagnosticFormat {
150 #[default]
151 Human,
152 Short,
153}
154
155pub mod build_info {
156 pub static VERSION: &str = env!("CARGO_PKG_VERSION");
158}