tinymist_world/package/
mod.rs1impl Notifier for DummyNotifier {}
2use std::num::NonZeroUsize;
3use std::{path::Path, sync::Arc};
4
5use ecow::EcoString;
6use tinymist_std::ImmutPath;
7use typst::diag::FileResult;
8pub use typst::diag::PackageError;
9pub use typst::syntax::package::PackageSpec;
10
11pub mod dummy;
12
13#[cfg(feature = "browser")]
14pub mod browser;
15
16#[cfg(feature = "http-registry")]
17pub mod http;
18
19pub trait PackageRegistry {
20 fn reset(&mut self) {}
21
22 fn revision(&self) -> Option<NonZeroUsize> {
23 None
24 }
25
26 fn resolve(&self, spec: &PackageSpec) -> Result<Arc<Path>, PackageError>;
27
28 fn packages(&self) -> &[(PackageSpec, Option<EcoString>)] {
35 &[]
36 }
37}
38
39pub struct RegistryPathMapper<T> {
40 pub registry: Arc<T>,
41}
42
43impl<T> RegistryPathMapper<T> {
44 pub fn new(registry: Arc<T>) -> Self {
45 Self { registry }
46 }
47}
48
49impl<T: PackageRegistry> tinymist_vfs::RootResolver for RegistryPathMapper<T> {
50 fn resolve_package_root(&self, pkg: &PackageSpec) -> FileResult<ImmutPath> {
51 Ok(self.registry.resolve(pkg)?)
52 }
53}
54
55pub trait Notifier {
56 fn downloading(&self, _spec: &PackageSpec) {}
57}
58
59#[derive(Debug, Default, Clone, Copy, Hash)]
60pub struct DummyNotifier;