mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-24 05:06:41 +00:00
feat: introduce dyn access model for futher development (#1898)
prepare for #1413 and #836
This commit is contained in:
parent
cf20c66b26
commit
f9c348c7d7
3 changed files with 48 additions and 5 deletions
|
|
@ -12,7 +12,8 @@ use tinymist_world::{args::*, WorldComputeGraph};
|
||||||
use tinymist_world::{
|
use tinymist_world::{
|
||||||
CompileSnapshot, CompilerFeat, CompilerUniverse, CompilerWorld, EntryOpts, EntryState,
|
CompileSnapshot, CompilerFeat, CompilerUniverse, CompilerWorld, EntryOpts, EntryState,
|
||||||
};
|
};
|
||||||
use typst::foundations::{Dict, Str, Value};
|
use typst::diag::FileResult;
|
||||||
|
use typst::foundations::{Bytes, Dict, Str, Value};
|
||||||
use typst::utils::LazyHash;
|
use typst::utils::LazyHash;
|
||||||
use typst::Features;
|
use typst::Features;
|
||||||
|
|
||||||
|
|
@ -30,7 +31,7 @@ impl CompilerFeat for LspCompilerFeat {
|
||||||
/// Uses [`FontResolverImpl`] directly.
|
/// Uses [`FontResolverImpl`] directly.
|
||||||
type FontResolver = FontResolverImpl;
|
type FontResolver = FontResolverImpl;
|
||||||
/// It accesses a physical file system.
|
/// It accesses a physical file system.
|
||||||
type AccessModel = SystemAccessModel;
|
type AccessModel = DynAccessModel;
|
||||||
/// It performs native HTTP requests for fetching package data.
|
/// It performs native HTTP requests for fetching package data.
|
||||||
type Registry = HttpRegistry;
|
type Registry = HttpRegistry;
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +78,7 @@ impl WorldProvider for CompileOnceArgs {
|
||||||
packages,
|
packages,
|
||||||
fonts,
|
fonts,
|
||||||
self.creation_timestamp,
|
self.creation_timestamp,
|
||||||
|
DynAccessModel(Arc::new(SystemAccessModel {})),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -170,6 +172,7 @@ impl WorldProvider for (ProjectInput, ImmutPath) {
|
||||||
packages,
|
packages,
|
||||||
Arc::new(fonts),
|
Arc::new(fonts),
|
||||||
None, // creation_timestamp - not available in project file context
|
None, // creation_timestamp - not available in project file context
|
||||||
|
DynAccessModel(Arc::new(SystemAccessModel {})),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -210,6 +213,7 @@ pub struct LspUniverseBuilder;
|
||||||
impl LspUniverseBuilder {
|
impl LspUniverseBuilder {
|
||||||
/// Create [`LspUniverse`] with the given options.
|
/// Create [`LspUniverse`] with the given options.
|
||||||
/// See [`LspCompilerFeat`] for instantiation details.
|
/// See [`LspCompilerFeat`] for instantiation details.
|
||||||
|
#[allow(clippy::too_many_arguments)]
|
||||||
pub fn build(
|
pub fn build(
|
||||||
entry: EntryState,
|
entry: EntryState,
|
||||||
export_target: ExportTarget,
|
export_target: ExportTarget,
|
||||||
|
|
@ -218,6 +222,7 @@ impl LspUniverseBuilder {
|
||||||
package_registry: HttpRegistry,
|
package_registry: HttpRegistry,
|
||||||
font_resolver: Arc<FontResolverImpl>,
|
font_resolver: Arc<FontResolverImpl>,
|
||||||
creation_timestamp: Option<i64>,
|
creation_timestamp: Option<i64>,
|
||||||
|
am: DynAccessModel,
|
||||||
) -> LspUniverse {
|
) -> LspUniverse {
|
||||||
let package_registry = Arc::new(package_registry);
|
let package_registry = Arc::new(package_registry);
|
||||||
let resolver = Arc::new(RegistryPathMapper::new(package_registry.clone()));
|
let resolver = Arc::new(RegistryPathMapper::new(package_registry.clone()));
|
||||||
|
|
@ -233,7 +238,7 @@ impl LspUniverseBuilder {
|
||||||
entry,
|
entry,
|
||||||
features,
|
features,
|
||||||
Some(inputs),
|
Some(inputs),
|
||||||
Vfs::new(resolver, SystemAccessModel {}),
|
Vfs::new(resolver, am),
|
||||||
package_registry,
|
package_registry,
|
||||||
font_resolver,
|
font_resolver,
|
||||||
creation_timestamp,
|
creation_timestamp,
|
||||||
|
|
@ -274,3 +279,37 @@ impl LspUniverseBuilder {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Access model for LSP universe and worlds.
|
||||||
|
pub trait LspAccessModel: Send + Sync {
|
||||||
|
/// Returns the content of a file entry.
|
||||||
|
fn content(&self, src: &Path) -> FileResult<Bytes>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> LspAccessModel for T
|
||||||
|
where
|
||||||
|
T: tinymist_world::vfs::PathAccessModel + Send + Sync + 'static,
|
||||||
|
{
|
||||||
|
fn content(&self, src: &Path) -> FileResult<Bytes> {
|
||||||
|
self.content(src)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Access model for LSP universe and worlds.
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct DynAccessModel(pub Arc<dyn LspAccessModel>);
|
||||||
|
|
||||||
|
impl DynAccessModel {
|
||||||
|
/// Create a new dynamic access model from the given access model.
|
||||||
|
pub fn new(access_model: Arc<dyn LspAccessModel>) -> Self {
|
||||||
|
Self(access_model)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl tinymist_world::vfs::PathAccessModel for DynAccessModel {
|
||||||
|
fn content(&self, src: &Path) -> FileResult<Bytes> {
|
||||||
|
self.0.content(src)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn reset(&mut self) {}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use tinymist_project::{
|
use tinymist_project::{
|
||||||
base::ShadowApi, font::FontResolverImpl, CompileFontArgs, EntryManager, EntryState,
|
base::ShadowApi, font::FontResolverImpl, vfs::system::SystemAccessModel, CompileFontArgs,
|
||||||
ExportTarget, LspUniverse, LspUniverseBuilder,
|
DynAccessModel, EntryManager, EntryState, ExportTarget, LspUniverse, LspUniverseBuilder,
|
||||||
};
|
};
|
||||||
use typst::{foundations::Bytes, syntax::VirtualPath};
|
use typst::{foundations::Bytes, syntax::VirtualPath};
|
||||||
|
|
||||||
|
|
@ -64,6 +64,7 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
|
||||||
LspUniverseBuilder::resolve_package(None, None),
|
LspUniverseBuilder::resolve_package(None, None),
|
||||||
FONT_RESOLVER.clone(),
|
FONT_RESOLVER.clone(),
|
||||||
None,
|
None,
|
||||||
|
DynAccessModel(Arc::new(SystemAccessModel {})),
|
||||||
);
|
);
|
||||||
let sources = source.split("-----");
|
let sources = source.split("-----");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
|
use reflexo_typst::vfs::system::SystemAccessModel;
|
||||||
use reflexo_typst::{diag::print_diagnostics, TypstDocument};
|
use reflexo_typst::{diag::print_diagnostics, TypstDocument};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
pub use tinymist_project::*;
|
pub use tinymist_project::*;
|
||||||
|
|
@ -200,6 +201,8 @@ impl ServerState {
|
||||||
packages,
|
packages,
|
||||||
fonts,
|
fonts,
|
||||||
creation_timestamp,
|
creation_timestamp,
|
||||||
|
// todo: impl an access model delegation to vscode's ssh-fs
|
||||||
|
DynAccessModel(Arc::new(SystemAccessModel {})),
|
||||||
);
|
);
|
||||||
|
|
||||||
// todo: unify filesystem watcher
|
// todo: unify filesystem watcher
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue