Skip to content

Commit

Permalink
dev: move package to reflexo_world part (#1177)
Browse files Browse the repository at this point in the history
* dev: move package to reflexo_world part

fix: compile error

* dev: update the package.json

* fix: compile error

* dev: remove dry compile
  • Loading branch information
Myriad-Dreamin authored Jan 16, 2025
1 parent 448ce48 commit 5659b0b
Show file tree
Hide file tree
Showing 17 changed files with 116 additions and 406 deletions.
76 changes: 52 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ env_logger = "0.11.3"
log = "0.4"

# Typst
reflexo = { version = "=0.5.1", default-features = false, features = [
reflexo = { version = "=0.5.4", default-features = false, features = [
"flat-vector",
] }
reflexo-world = { version = "=0.5.1", features = ["system"] }
reflexo-typst = { version = "=0.5.1", features = [
reflexo-world = { version = "=0.5.4", features = ["system"] }
reflexo-typst = { version = "=0.5.4", features = [
"system",
], default-features = false }
reflexo-vec2svg = { version = "=0.5.1" }
reflexo-typst-shim = { version = "=0.5.1", features = ["nightly"] }
reflexo-vec2svg = { version = "=0.5.4" }
reflexo-typst-shim = { version = "=0.5.4", features = ["nightly"] }


typst = "0.12.0"
Expand Down
3 changes: 2 additions & 1 deletion crates/tinymist-query/src/docs/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use std::sync::{Arc, LazyLock};

use ecow::{eco_format, EcoString};
use parking_lot::Mutex;
use tinymist_world::base::{EntryState, ShadowApi, TaskInputs};
use tinymist_world::base::{EntryState, ShadowApi};
use tinymist_world::TaskInputs;
use typlite::scopes::Scopes;
use typlite::value::Value;
use typlite::TypliteFeat;
Expand Down
4 changes: 2 additions & 2 deletions crates/tinymist-query/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use parking_lot::Mutex;
use reflexo_typst::typst::prelude::*;
use reflexo_typst::{package::PackageSpec, TypstFileId};
use serde::{Deserialize, Serialize};
use tinymist_world::package::HttpsRegistry;
use tinymist_world::package::http::HttpRegistry;
use typst::diag::{EcoString, StrResult};
use typst::syntax::package::PackageManifest;
use typst::syntax::VirtualPath;
Expand Down Expand Up @@ -78,7 +78,7 @@ pub fn check_package(ctx: &mut LocalContext, spec: &PackageInfo) -> StrResult<()

/// Get the packages in namespaces and their descriptions.
pub fn list_package_by_namespace(
registry: &HttpsRegistry,
registry: &HttpRegistry,
ns: EcoString,
) -> EcoVec<(PathBuf, PackageSpec)> {
// search packages locally. We only search in the data
Expand Down
20 changes: 9 additions & 11 deletions crates/tinymist-query/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ use std::{
use once_cell::sync::Lazy;
use reflexo_typst::package::PackageSpec;
use reflexo_typst::world::EntryState;
use reflexo_typst::{CompileDriverImpl, EntryManager, EntryReader, ShadowApi, TaskInputs};
use reflexo_typst::{Compiler, EntryManager, EntryReader, ShadowApi};
use serde_json::{ser::PrettyFormatter, Serializer, Value};
use tinymist_world::CompileFontArgs;
use tinymist_world::TaskInputs;
use typst::foundations::Bytes;
use typst::syntax::ast::{self, AstNode};
use typst::syntax::{FileId as TypstFileId, LinkedNode, Source, SyntaxKind, VirtualPath};
Expand All @@ -31,8 +32,6 @@ use crate::{
};
use crate::{to_lsp_position, CompletionFeat, LspWorldExt};

type CompileDriver<C> = CompileDriverImpl<C, tinymist_world::LspCompilerFeat>;

pub fn snapshot_testing(name: &str, f: &impl Fn(&mut LocalContext, PathBuf)) {
let name = if name.is_empty() { "playground" } else { name };

Expand Down Expand Up @@ -147,7 +146,7 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
} else {
PathBuf::from("/")
};
let mut world = LspUniverseBuilder::build(
let mut verse = LspUniverseBuilder::build(
EntryState::new_rooted(root.as_path().into(), None),
Default::default(),
Arc::new(
Expand Down Expand Up @@ -181,19 +180,18 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
let path = path.unwrap_or_else(|| format!("/s{idx}.typ"));

let pw = root.join(Path::new(&path));
world
verse
.map_shadow(&pw, Bytes::from(source.as_bytes()))
.unwrap();
last_pw = Some(pw);
}

world.mutate_entry(EntryState::new_detached()).unwrap();
let mut driver = CompileDriver::new(std::marker::PhantomData, world);
let _ = driver.compile(&mut Default::default());
verse.mutate_entry(EntryState::new_detached()).unwrap();
let world = verse.snapshot();
let _ = std::marker::PhantomData.compile(&world, &mut Default::default());

let pw = last_pw.unwrap();
driver
.universe_mut()
verse
.mutate_entry(EntryState::new_rooted(
root.as_path().into(),
Some(TypstFileId::new(
Expand All @@ -202,7 +200,7 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
)),
))
.unwrap();
f(driver.universe_mut(), pw)
f(&mut verse, pw)
}

pub fn find_test_range(s: &Source) -> Range<usize> {
Expand Down
18 changes: 11 additions & 7 deletions crates/tinymist-world/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub use reflexo_typst;
pub use reflexo_typst::config::CompileFontOpts;
pub use reflexo_typst::error::prelude;
pub use reflexo_typst::world as base;
pub use reflexo_typst::world::{package, CompilerUniverse, CompilerWorld, Revising, TaskInputs};
pub use reflexo_typst::{entry::*, vfs, EntryOpts, EntryState};

use std::path::Path;
Expand All @@ -17,13 +18,12 @@ use clap::{builder::ValueParser, ArgAction, Parser};
use reflexo_typst::error::prelude::*;
use reflexo_typst::font::system::SystemFontSearcher;
use reflexo_typst::foundations::{Str, Value};
use reflexo_typst::package::http::HttpRegistry;
use reflexo_typst::vfs::{system::SystemAccessModel, Vfs};
use reflexo_typst::{CompilerFeat, CompilerUniverse, CompilerWorld, ImmutPath, TypstDict};
use reflexo_typst::{CompilerFeat, ImmutPath, TypstDict};
use serde::{Deserialize, Serialize};

pub mod font;
pub mod package;
use package::HttpsRegistry;

const ENV_PATH_SEP: char = if cfg!(windows) { ';' } else { ':' };

Expand All @@ -38,7 +38,7 @@ impl CompilerFeat for SystemCompilerFeatExtend {
/// It accesses a physical file system.
type AccessModel = SystemAccessModel;
/// It performs native HTTP requests for fetching package data.
type Registry = HttpsRegistry;
type Registry = HttpRegistry;
}

/// The compiler universe in system environment.
Expand Down Expand Up @@ -211,7 +211,7 @@ impl LspUniverseBuilder {
entry: EntryState,
inputs: ImmutDict,
font_resolver: Arc<TinymistFontResolver>,
package_registry: HttpsRegistry,
package_registry: HttpRegistry,
) -> ZResult<LspUniverse> {
Ok(LspUniverse::new_raw(
entry,
Expand All @@ -238,8 +238,12 @@ impl LspUniverseBuilder {
pub fn resolve_package(
cert_path: Option<ImmutPath>,
args: Option<&CompilePackageArgs>,
) -> HttpsRegistry {
HttpsRegistry::new(cert_path, args)
) -> HttpRegistry {
HttpRegistry::new(
cert_path,
args.and_then(|args| Some(args.package_path.clone()?.into())),
args.and_then(|args| Some(args.package_cache_path.clone()?.into())),
)
}
}

Expand Down
Loading

0 comments on commit 5659b0b

Please sign in to comment.