dev: make eval compat (#1269)

* fix: compile when preview feature is disabled

* build: update cargo.lock

* old

* old

* old

* back
This commit is contained in:
Myriad-Dreamin 2025-02-08 14:54:57 +08:00
parent 5b2b34ee9e
commit d0188a768e
12 changed files with 68 additions and 28 deletions

View file

@ -3,7 +3,7 @@
//! Note, this is used for the completion of parameters on a function's
//! *definition* instead of the completion of arguments of some *function call*.
use typst::eval::CapturesVisitor;
use typst_shim::eval::CapturesVisitor;
use super::*;
impl CompletionPair<'_, '_, '_> {

View file

@ -14,12 +14,11 @@ use tinymist_std::hash::{hash128, FxDashMap};
use tinymist_world::vfs::{PathResolution, WorkspaceResolver};
use tinymist_world::{EntryReader, DETACHED_ENTRY};
use typst::diag::{eco_format, At, FileError, FileResult, SourceResult, StrResult};
use typst::engine::{Route, Sink, Traced};
use typst::eval::Eval;
use typst::foundations::{Bytes, Module, Styles};
use typst::layout::Position;
use typst::syntax::package::{PackageManifest, PackageSpec};
use typst::syntax::{Span, VirtualPath};
use typst_shim::eval::{eval_compat, Eval};
use crate::adt::revision::{RevisionLock, RevisionManager, RevisionManagerLike, RevisionSlot};
use crate::analysis::prelude::*;
@ -401,7 +400,7 @@ impl LocalContext {
self.shared_().preload_package(entry_point);
}
pub(crate) fn with_vm<T>(&self, f: impl FnOnce(&mut typst::eval::Vm) -> T) -> T {
pub(crate) fn with_vm<T>(&self, f: impl FnOnce(&mut typst_shim::eval::Vm) -> T) -> T {
crate::upstream::with_vm((self.world() as &dyn World).track(), f)
}
@ -671,17 +670,7 @@ impl SharedContext {
/// Get (Create) a module by source.
pub fn module_by_src(&self, source: Source) -> SourceResult<Module> {
let route = Route::default();
let traced = Traced::default();
let mut sink = Sink::default();
typst::eval::eval(
((&self.world) as &dyn World).track(),
traced.track(),
sink.track_mut(),
route.track(),
&source,
)
eval_compat(&self.world, &source)
}
/// Try to load a module from the current source file.

View file

@ -78,7 +78,7 @@ pub fn analyze_import_(world: &dyn World, source: &SyntaxNode) -> (Option<Value>
Scopes::new(Some(world.library())),
Span::detached(),
);
let module = typst::eval::import(&mut vm, source.clone(), source_span, true)
let module = typst_shim::eval::import(&mut vm, source.clone(), source_span, true)
.ok()
.map(Value::Module);

View file

@ -423,12 +423,15 @@ pub fn truncated_repr(value: &Value) -> EcoString {
}
/// Run a function with a VM instance in the world
pub fn with_vm<T>(world: Tracked<dyn World + '_>, f: impl FnOnce(&mut typst::eval::Vm) -> T) -> T {
pub fn with_vm<T>(
world: Tracked<dyn World + '_>,
f: impl FnOnce(&mut typst_shim::eval::Vm) -> T,
) -> T {
use comemo::Track;
use typst::engine::*;
use typst::eval::*;
use typst::foundations::*;
use typst::introspection::*;
use typst_shim::eval::*;
let introspector = Introspector::default();
let traced = Traced::default();

View file

@ -3,11 +3,11 @@ use std::fmt::Write;
use ecow::{eco_format, EcoString};
use if_chain::if_chain;
use typst::engine::Sink;
use typst::eval::CapturesVisitor;
use typst::foundations::{repr, Capturer, CastInfo, Value};
use typst::layout::Length;
use typst::syntax::{ast, LinkedNode, Source, SyntaxKind};
use typst::World;
use typst_shim::eval::CapturesVisitor;
use typst_shim::syntax::LinkedNodeExt;
use typst_shim::utils::{round_2, Numeric};