mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-11-24 21:19:37 +00:00
feat: add js package registry support for tinymist-wasm (#2102)
Some checks failed
tinymist::auto_tag / auto-tag (push) Has been cancelled
tinymist::ci / Duplicate Actions Detection (push) Has been cancelled
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Has been cancelled
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Has been cancelled
tinymist::ci / prepare-build (push) Has been cancelled
tinymist::gh_pages / build-gh-pages (push) Has been cancelled
tinymist::ci / announce (push) Has been cancelled
tinymist::ci / build (push) Has been cancelled
Some checks failed
tinymist::auto_tag / auto-tag (push) Has been cancelled
tinymist::ci / Duplicate Actions Detection (push) Has been cancelled
tinymist::ci / Check Clippy, Formatting, Completion, Documentation, and Tests (Linux) (push) Has been cancelled
tinymist::ci / Check Minimum Rust version and Tests (Windows) (push) Has been cancelled
tinymist::ci / prepare-build (push) Has been cancelled
tinymist::gh_pages / build-gh-pages (push) Has been cancelled
tinymist::ci / announce (push) Has been cancelled
tinymist::ci / build (push) Has been cancelled
Co-authored-by: Myriad-Dreamin <camiyoru@gmail.com>
This commit is contained in:
parent
c8e723fac7
commit
b239224a63
10 changed files with 278 additions and 79 deletions
|
|
@ -34,7 +34,9 @@ tinymist-l10n.workspace = true
|
|||
toml = { workspace = true, optional = true }
|
||||
typst.workspace = true
|
||||
typst-assets.workspace = true
|
||||
notify.workspace = true
|
||||
notify = { workspace = true, optional = true }
|
||||
js-sys = { workspace = true, optional = true }
|
||||
wasm-bindgen = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
|
||||
|
|
@ -43,8 +45,8 @@ no-content-hint = ["tinymist-task/no-content-hint"]
|
|||
lsp = ["toml"]
|
||||
# "system",
|
||||
|
||||
system = ["tinymist-std/system", "tinymist-world/system", "toml"]
|
||||
web = ["tinymist-std/web", "tinymist-world/web"]
|
||||
system = ["tinymist-std/system", "tinymist-world/system", "toml", "notify"]
|
||||
web = ["tinymist-std/web", "tinymist-world/web", "js-sys", "wasm-bindgen"]
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ use tinymist_std::ImmutPath;
|
|||
use tinymist_std::error::prelude::*;
|
||||
use tinymist_task::ExportTarget;
|
||||
use tinymist_world::package::RegistryPathMapper;
|
||||
#[cfg(all(not(feature = "system"), feature = "web"))]
|
||||
use tinymist_world::package::registry::ProxyContext;
|
||||
use tinymist_world::vfs::Vfs;
|
||||
use tinymist_world::{
|
||||
CompileSnapshot, CompilerFeat, CompilerUniverse, CompilerWorld, EntryOpts, EntryState,
|
||||
|
|
@ -28,12 +30,11 @@ impl CompilerFeat for LspCompilerFeat {
|
|||
type FontResolver = FontResolverImpl;
|
||||
/// It accesses a physical file system.
|
||||
type AccessModel = DynAccessModel;
|
||||
/// It performs native HTTP requests for fetching package data.
|
||||
#[cfg(feature = "system")]
|
||||
type Registry = tinymist_world::package::registry::HttpRegistry;
|
||||
// todo: registry in browser
|
||||
#[cfg(not(feature = "system"))]
|
||||
type Registry = tinymist_world::package::registry::DummyRegistry;
|
||||
/// It performs:
|
||||
/// - native HTTP requests for fetching package data in system environment
|
||||
/// - js proxied requests to browser environment
|
||||
/// - no package registry in other environments
|
||||
type Registry = LspRegistry;
|
||||
}
|
||||
|
||||
/// LSP universe that spawns LSP worlds.
|
||||
|
|
@ -211,10 +212,12 @@ impl WorldProvider for (crate::ProjectInput, ImmutPath) {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "system"))]
|
||||
type LspRegistry = tinymist_world::package::registry::DummyRegistry;
|
||||
#[cfg(all(not(feature = "system"), feature = "web"))]
|
||||
type LspRegistry = tinymist_world::package::registry::JsRegistry;
|
||||
#[cfg(feature = "system")]
|
||||
type LspRegistry = tinymist_world::package::registry::HttpRegistry;
|
||||
#[cfg(not(any(feature = "system", feature = "web")))]
|
||||
type LspRegistry = tinymist_world::package::registry::DummyRegistry;
|
||||
|
||||
/// Builder for LSP universe.
|
||||
pub struct LspUniverseBuilder;
|
||||
|
|
@ -318,7 +321,20 @@ impl LspUniverseBuilder {
|
|||
}
|
||||
|
||||
/// Resolves package registry from given options.
|
||||
#[cfg(not(feature = "system"))]
|
||||
#[cfg(all(not(feature = "system"), feature = "web"))]
|
||||
pub fn resolve_package(
|
||||
_cert_path: Option<ImmutPath>,
|
||||
_args: Option<&CompilePackageArgs>,
|
||||
resolve_fn: js_sys::Function,
|
||||
) -> tinymist_world::package::registry::JsRegistry {
|
||||
tinymist_world::package::registry::JsRegistry {
|
||||
context: ProxyContext::new(wasm_bindgen::JsValue::NULL),
|
||||
real_resolve_fn: resolve_fn,
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves package registry from given options.
|
||||
#[cfg(not(any(feature = "system", feature = "web")))]
|
||||
pub fn resolve_package(
|
||||
_cert_path: Option<ImmutPath>,
|
||||
_args: Option<&CompilePackageArgs>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue