1use std::{fmt::Debug, sync::Arc};
2
3use tinymist_std::ImmutPath;
4use typst::diag::FileResult;
5
6use crate::{path_mapper::RootResolver, AccessModel, Bytes, PathAccessModel, TypstFileId};
7
8#[derive(Clone)]
10pub struct ResolveAccessModel<M> {
11 pub resolver: Arc<dyn RootResolver + Send + Sync>,
12 pub inner: M,
13}
14
15impl<M> Debug for ResolveAccessModel<M> {
16 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
17 f.debug_struct("ResolveAccessModel").finish()
18 }
19}
20
21impl<M: PathAccessModel> AccessModel for ResolveAccessModel<M> {
22 #[inline]
23 fn reset(&mut self) {
24 self.inner.reset();
25 }
26
27 fn content(&self, fid: TypstFileId) -> (Option<ImmutPath>, FileResult<Bytes>) {
28 let resolved = Ok(()).and_then(|_| self.resolver.path_for_id(fid)?.to_err());
29
30 match resolved {
31 Ok(path) => (Some(path.as_path().into()), self.inner.content(&path)),
32 Err(e) => (None, Err(e)),
33 }
34 }
35}