#![allow(missing_docs)]
pub mod args;
pub mod config;
pub mod debug_loc;
pub mod entry;
pub mod font;
pub mod package;
pub mod parser;
pub mod source;
pub mod world;
pub use compute::*;
pub use entry::*;
pub use snapshot::*;
pub use world::*;
pub use tinymist_vfs as vfs;
mod compute;
mod snapshot;
#[cfg(feature = "system")]
pub mod system;
#[cfg(feature = "system")]
pub use system::{print_diagnostics, SystemCompilerFeat, TypstSystemUniverse, TypstSystemWorld};
#[cfg(feature = "browser")]
pub(crate) mod browser;
#[cfg(feature = "browser")]
pub use browser::{BrowserCompilerFeat, TypstBrowserUniverse, TypstBrowserWorld};
use std::{path::Path, sync::Arc};
use ecow::EcoVec;
use tinymist_vfs::PathAccessModel as VfsAccessModel;
use typst::diag::{At, FileResult, SourceResult};
use typst::foundations::Bytes;
use typst::syntax::{FileId, Span};
use font::FontResolver;
use package::PackageRegistry;
pub trait ShadowApi {
fn shadow_paths(&self) -> Vec<Arc<Path>>;
fn shadow_ids(&self) -> Vec<FileId>;
fn reset_shadow(&mut self) {
for path in self.shadow_paths() {
self.unmap_shadow(&path).unwrap();
}
}
fn map_shadow(&mut self, path: &Path, content: Bytes) -> FileResult<()>;
fn unmap_shadow(&mut self, path: &Path) -> FileResult<()>;
fn map_shadow_by_id(&mut self, file_id: FileId, content: Bytes) -> FileResult<()>;
fn unmap_shadow_by_id(&mut self, file_id: FileId) -> FileResult<()>;
}
pub trait ShadowApiExt {
fn with_shadow_file<T>(
&mut self,
file_path: &Path,
content: Bytes,
f: impl FnOnce(&mut Self) -> SourceResult<T>,
) -> SourceResult<T>;
fn with_shadow_file_by_id<T>(
&mut self,
file_id: FileId,
content: Bytes,
f: impl FnOnce(&mut Self) -> SourceResult<T>,
) -> SourceResult<T>;
}
impl<C: ShadowApi> ShadowApiExt for C {
fn with_shadow_file<T>(
&mut self,
file_path: &Path,
content: Bytes,
f: impl FnOnce(&mut Self) -> SourceResult<T>,
) -> SourceResult<T> {
self.map_shadow(file_path, content).at(Span::detached())?;
let res: Result<T, EcoVec<typst::diag::SourceDiagnostic>> = f(self);
self.unmap_shadow(file_path).at(Span::detached())?;
res
}
fn with_shadow_file_by_id<T>(
&mut self,
file_id: FileId,
content: Bytes,
f: impl FnOnce(&mut Self) -> SourceResult<T>,
) -> SourceResult<T> {
self.map_shadow_by_id(file_id, content)
.at(Span::detached())?;
let res: Result<T, EcoVec<typst::diag::SourceDiagnostic>> = f(self);
self.unmap_shadow_by_id(file_id).at(Span::detached())?;
res
}
}
pub trait WorldDeps {
fn iter_dependencies(&self, f: &mut dyn FnMut(FileId));
}
pub trait CompilerFeat: Send + Sync + 'static {
type FontResolver: FontResolver + Send + Sync + Sized;
type AccessModel: VfsAccessModel + Clone + Send + Sync + Sized;
type Registry: PackageRegistry + Send + Sync + Sized;
}
#[derive(Debug, Copy, Clone, Default, Eq, PartialEq, Ord, PartialOrd)]
pub enum DiagnosticFormat {
#[default]
Human,
Short,
}
pub mod build_info {
pub static VERSION: &str = env!("CARGO_PKG_VERSION");
}