Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: upgrade typst to 4f3ba7f8caecc49ae1051f0a0c217a44d3fda876 #946

Open
wants to merge 2 commits into
base: nightly/v0.12.9
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
327 changes: 207 additions & 120 deletions Cargo.lock

Large diffs are not rendered by default.

36 changes: 19 additions & 17 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,23 @@ env_logger = "0.11.3"
log = "0.4"

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


typst = "0.12.0"
typst-timing = "0.12.0"
typst-svg = "0.12.0"
typst-render = "0.12.0"
typst-pdf = "0.12.0"
typst-eval = "0.12.0"
typst-syntax = "0.12.0"
typst-assets = "0.12.0"
typstfmt_lib = { git = "https://github.com/astrale-sharp/typstfmt", tag = "0.2.7" }
Expand Down Expand Up @@ -194,12 +195,13 @@ extend-exclude = ["/.git", "fixtures", "upstream"]

# tinymist-assets = { path = "./crates/tinymist-assets/" }

typst = { git = "https://github.com/Myriad-Dreamin/typst.git", tag = "tinymist-v0.12.0" }
typst-timing = { git = "https://github.com/Myriad-Dreamin/typst.git", tag = "tinymist-v0.12.0" }
typst-svg = { git = "https://github.com/Myriad-Dreamin/typst.git", tag = "tinymist-v0.12.0" }
typst-render = { git = "https://github.com/Myriad-Dreamin/typst.git", tag = "tinymist-v0.12.0" }
typst-pdf = { git = "https://github.com/Myriad-Dreamin/typst.git", tag = "tinymist-v0.12.0" }
typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", tag = "tinymist-v0.12.0" }
typst = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.12.9" }
typst-timing = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.12.9" }
typst-svg = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.12.9" }
typst-render = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.12.9" }
typst-pdf = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.12.9" }
typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.12.9" }
typst-eval = { git = "https://github.com/Myriad-Dreamin/typst.git", branch = "tinymist-v0.12.9" }

# typst = { path = "../typst/crates/typst" }
# typst-timing = { path = "../typst/crates/typst-timing" }
Expand All @@ -208,12 +210,12 @@ typst-syntax = { git = "https://github.com/Myriad-Dreamin/typst.git", tag = "tin
# typst-render = { path = "../typst/crates/typst-render" }
# typst-syntax = { path = "../typst/crates/typst-syntax" }

# reflexo = { git = "https://github.com/Myriad-Dreamin/typst.ts/", rev = "26e2eaa3696845a178df3266edc0019c77396414" }
# world = { git = "https://github.com/Myriad-Dreamin/typst.ts/", rev = "26e2eaa3696845a178df3266edc0019c77396414" }
# typst = { git = "https://github.com/Myriad-Dreamin/typst.ts/", rev = "26e2eaa3696845a178df3266edc0019c77396414" }
# typst2vec = { git = "https://github.com/Myriad-Dreamin/typst.ts/", rev = "26e2eaa3696845a178df3266edc0019c77396414" }
# vec2svg = { git = "https://github.com/Myriad-Dreamin/typst.ts/", rev = "26e2eaa3696845a178df3266edc0019c77396414" }
# shim = { git = "https://github.com/Myriad-Dreamin/typst.ts/", rev = "26e2eaa3696845a178df3266edc0019c77396414" }
reflexo = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-world = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-typst = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-typst2vec = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-vec2svg = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }
reflexo-typst-shim = { git = "https://github.com/Myriad-Dreamin/typst.ts/", branch = "nightly/v0.5.3" }

# reflexo = { path = "../typst.ts/crates/reflexo/" }
# reflexo-world = { path = "../typst.ts/crates/reflexo-world/" }
Expand Down
3 changes: 2 additions & 1 deletion crates/tinymist-query/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ repository.workspace = true
rust-version.workspace = true

[features]
default = ["no-content-hint"]
default = []

no-content-hint = ["reflexo-typst/no-content-hint"]

Expand Down Expand Up @@ -44,6 +44,7 @@ rpds.workspace = true
rayon.workspace = true

typst.workspace = true
typst-eval.workspace = true

reflexo.workspace = true
typst-shim.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion crates/tinymist-query/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ mod call_info_tests {
};

let mut w = ci.arg_mapping.iter().collect::<Vec<_>>();
w.sort_by(|x, y| x.0.span().number().cmp(&y.0.span().number()));
w.sort_by(|x, y| x.0.span().into_raw().cmp(&y.0.span().into_raw()));

for (arg, arg_call_info) in w {
writeln!(f, "{} -> {:?}", arg.clone().into_text(), arg_call_info)?;
Expand Down
3 changes: 2 additions & 1 deletion crates/tinymist-query/src/analysis/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use typst::foundations::{IntoValue, Label, Selector, Type};
use typst::introspection::Introspector;
use typst::model::BibliographyElem;
use typst::utils::PicoStr;

use super::{prelude::*, InsTy, SharedContext};
use crate::syntax::{Decl, DeclExpr, DerefTarget, Expr, ExprInfo};
Expand Down Expand Up @@ -157,7 +158,7 @@ fn find_ref_definition(
name: &str,
ref_expr: ast::Expr,
) -> Option<Definition> {
let label = Label::new(name);
let label = Label::new(PicoStr::intern(name));
let sel = Selector::Label(label);

// if it is a label, we put the selection range to itself
Expand Down
11 changes: 6 additions & 5 deletions crates/tinymist-query/src/analysis/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use reflexo::debug_loc::DataSource;
use reflexo::hash::{hash128, FxDashMap};
use reflexo_typst::TypstDocument;
use reflexo_typst::{EntryReader, WorldDeps};
use rustc_hash::FxHashMap;
use tinymist_world::LspWorld;
use tinymist_world::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::model::Document;
use typst::syntax::package::PackageManifest;
use typst::syntax::{package::PackageSpec, Span, VirtualPath};
use typst_eval::Eval;

use crate::adt::revision::{RevisionLock, RevisionManager, RevisionManagerLike, RevisionSlot};
use crate::analysis::prelude::*;
Expand Down Expand Up @@ -374,7 +374,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_eval::Vm) -> T) -> T {
crate::upstream::with_vm((self.world() as &dyn World).track(), f)
}

Expand Down Expand Up @@ -657,7 +657,8 @@ impl SharedContext {
let traced = Traced::default();
let mut sink = Sink::default();

typst::eval::eval(
typst_eval::eval(
&typst::ROUTINES,
((&self.world) as &dyn World).track(),
traced.track(),
sink.track_mut(),
Expand Down Expand Up @@ -881,7 +882,7 @@ impl SharedContext {
/// only generated when the document is available.
pub fn tooltip(
&self,
document: Option<&Document>,
document: Option<&TypstDocument>,
source: &Source,
cursor: usize,
) -> Option<Tooltip> {
Expand Down
31 changes: 14 additions & 17 deletions crates/tinymist-query/src/analysis/track_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

use comemo::Track;
use ecow::*;
use reflexo::typst::TypstDocument;
use typst::engine::{Engine, Route, Sink, Traced};
use typst::eval::Vm;
use typst::foundations::{Context, Label, Scopes, Styles, Value};
use typst::foundations::{Label, Styles, Value};
use typst::introspection::Introspector;
use typst::model::{BibliographyElem, Document};
use typst::syntax::{ast, LinkedNode, Span, SyntaxKind, SyntaxNode};
use typst::model::BibliographyElem;
use typst::syntax::{ast, LinkedNode, SyntaxKind, SyntaxNode};
use typst::World;

/// Try to determine a set of possible values for an expression.
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn analyze_expr_(world: &dyn World, node: &SyntaxNode) -> EcoVec<(Value, Opt
}
}

return typst::trace(world, node.span());
return typst::trace::<TypstDocument>(world, node.span());
}
};

Expand All @@ -62,23 +62,20 @@ pub fn analyze_import_(world: &dyn World, source: &SyntaxNode) -> (Option<Value>
let introspector = Introspector::default();
let traced = Traced::default();
let mut sink = Sink::new();
let engine = Engine {
let mut engine = Engine {
routines: &typst::ROUTINES,
world: world.track(),
route: Route::default(),
introspector: introspector.track(),
traced: traced.track(),
sink: sink.track_mut(),
};

let context = Context::none();
let mut vm = Vm::new(
engine,
context.track(),
Scopes::new(Some(world.library())),
Span::detached(),
);
let module = typst::eval::import(&mut vm, source.clone(), source_span, true)
let module = source
.clone()
.cast::<typst::foundations::Str>()
.ok()
.and_then(|source| typst_eval::import(&mut engine, source.as_str(), source_span).ok())
.map(Value::Module);

(Some(source), module)
Expand All @@ -103,7 +100,7 @@ pub struct DynLabel {
/// - All labels and descriptions for them, if available
/// - A split offset: All labels before this offset belong to nodes, all after
/// belong to a bibliography.
pub fn analyze_labels(document: &Document) -> (Vec<DynLabel>, usize) {
pub fn analyze_labels(document: &TypstDocument) -> (Vec<DynLabel>, usize) {
let mut output = vec![];

// Labels in the document.
Expand Down Expand Up @@ -136,9 +133,9 @@ pub fn analyze_labels(document: &Document) -> (Vec<DynLabel>, usize) {
let split = output.len();

// Bibliography keys.
for (key, detail) in BibliographyElem::keys(document.introspector.track()) {
for (label, detail) in BibliographyElem::keys(document.introspector.track()) {
output.push(DynLabel {
label: Label::new(key.as_str()),
label,
label_desc: detail.clone(),
detail: detail.clone(),
bib_title: detail,
Expand Down
6 changes: 2 additions & 4 deletions crates/tinymist-query/src/document_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::sync::Arc;
use std::{collections::HashMap, path::PathBuf};

use reflexo::debug_loc::DataSource;
use reflexo_typst::TypstDocument;
use serde::{Deserialize, Serialize};
use typst::text::{Font, FontStretch, FontStyle, FontWeight};
use typst::{
layout::{Frame, FrameItem},
model::Document,
syntax::Span,
text::TextItem,
};
Expand Down Expand Up @@ -142,7 +142,7 @@ struct DocumentMetricsWorker<'a> {
}

impl DocumentMetricsWorker<'_> {
fn work(&mut self, doc: &Document) -> Option<()> {
fn work(&mut self, doc: &TypstDocument) -> Option<()> {
for page in &doc.pages {
self.work_frame(&page.frame)?;
}
Expand All @@ -166,8 +166,6 @@ impl DocumentMetricsWorker<'_> {
| FrameItem::Image(..)
| FrameItem::Tag(..)
| FrameItem::Link(..) => Some(()),
#[cfg(not(feature = "no-content-hint"))]
FrameItem::ContentHint(..) => Some(()),
}
}

Expand Down
13 changes: 9 additions & 4 deletions crates/tinymist-query/src/jump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

use std::num::NonZeroUsize;

use typst::model::Document;
use reflexo_typst::TypstDocument;
use typst::{
layout::{Frame, FrameItem, Point, Position},
syntax::{LinkedNode, Source, Span, SyntaxKind},
};
use typst_shim::syntax::LinkedNodeExt;

/// Find the output location in the document for a cursor position.
pub fn jump_from_cursor(document: &Document, source: &Source, cursor: usize) -> Option<Position> {
pub fn jump_from_cursor(
document: &TypstDocument,
source: &Source,
cursor: usize,
) -> Option<Position> {
let node = LinkedNode::new(source.root()).leaf_at_compat(cursor)?;
if node.kind() != SyntaxKind::Text {
return None;
Expand Down Expand Up @@ -47,7 +51,7 @@ pub fn jump_from_cursor(document: &Document, source: &Source, cursor: usize) ->
}

/// Find the position of a span in a frame.
fn find_in_frame(frame: &Frame, span: Span, min_dis: &mut u64, p: &mut Point) -> Option<Point> {
pub fn find_in_frame(frame: &Frame, span: Span, min_dis: &mut u64, p: &mut Point) -> Option<Point> {
for (mut pos, item) in frame.items() {
if let FrameItem::Group(group) = item {
// TODO: Handle transformation.
Expand All @@ -62,7 +66,8 @@ fn find_in_frame(frame: &Frame, span: Span, min_dis: &mut u64, p: &mut Point) ->
return Some(pos);
}
if glyph.span.0.id() == span.id() {
let dis = glyph.span.0.number().abs_diff(span.number());
let glyph_span = glyph.span.0.into_raw();
let dis = glyph_span.get().abs_diff(span.into_raw().get());
if dis < *min_dis {
*min_dis = dis;
*p = pos;
Expand Down
3 changes: 2 additions & 1 deletion crates/tinymist-query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ mod prelude;

use std::sync::Arc;

use typst::{model::Document as TypstDocument, syntax::Source};
use reflexo_typst::TypstDocument;
use typst::syntax::Source;

/// The physical position in a document.
pub type FramePosition = typst::layout::Position;
Expand Down
2 changes: 1 addition & 1 deletion crates/tinymist-query/src/syntax/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ impl Ord for Decl {
(Self::Generated(l), Self::Generated(r)) => l.0 .0.cmp(&r.0 .0),
(Self::Module(l), Self::Module(r)) => l.fid.cmp(&r.fid),
(Self::Docs(l), Self::Docs(r)) => l.var.cmp(&r.var).then_with(|| l.base.cmp(&r.base)),
_ => self.span().number().cmp(&other.span().number()),
_ => self.span().into_raw().cmp(&other.span().into_raw()),
};

base.then_with(|| self.name().cmp(other.name()))
Expand Down
2 changes: 1 addition & 1 deletion crates/tinymist-query/src/syntax/docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl DocsChecker<'_> {
Type::of::<typst::visualize::Color>(),
Type::of::<typst::visualize::Gradient>(),
Type::of::<typst::visualize::Pattern>(),
Type::of::<typst::symbols::Symbol>(),
Type::of::<typst::foundations::Symbol>(),
Type::of::<typst::foundations::Version>(),
Type::of::<typst::foundations::Bytes>(),
Type::of::<typst::foundations::Label>(),
Expand Down
8 changes: 4 additions & 4 deletions crates/tinymist-query/src/upstream/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ use std::ops::Range;
use ecow::{eco_format, EcoString};
use if_chain::if_chain;
use lsp_types::TextEdit;
use reflexo_typst::TypstDocument;
use serde::{Deserialize, Serialize};
use typst::foundations::{fields_on, format_str, repr, Repr, StyleChain, Styles, Value};
use typst::model::Document;
use typst::syntax::{ast, is_id_continue, is_id_start, is_ident, LinkedNode, Source, SyntaxKind};
use typst::text::RawElem;
use typst::World;
Expand Down Expand Up @@ -801,7 +801,7 @@ fn code_completions(ctx: &mut CompletionContext, hash: bool) {
/// Context for autocompletion.
pub struct CompletionContext<'a> {
pub ctx: &'a mut LocalContext,
pub document: Option<&'a Document>,
pub document: Option<&'a TypstDocument>,
pub text: &'a str,
pub before: &'a str,
pub after: &'a str,
Expand All @@ -825,7 +825,7 @@ impl<'a> CompletionContext<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
ctx: &'a mut LocalContext,
document: Option<&'a Document>,
document: Option<&'a TypstDocument>,
source: &'a Source,
cursor: usize,
explicit: bool,
Expand Down Expand Up @@ -996,7 +996,7 @@ impl<'a> CompletionContext<'a> {
if !self.seen_casts.insert(hash128(&label)) {
continue;
}
let label: EcoString = label.as_str().into();
let label: EcoString = label.resolve().as_str().into();
let completion = Completion {
kind: CompletionKind::Reference,
apply: Some(eco_format!(
Expand Down
2 changes: 1 addition & 1 deletion crates/tinymist-query/src/upstream/complete/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl CompletionContext<'_> {

let cursor_mode = interpret_mode_at(Some(node));
let is_content = value.ty() == Type::of::<Content>()
|| value.ty() == Type::of::<typst::symbols::Symbol>();
|| value.ty() == Type::of::<typst::foundations::Symbol>();
crate::log_debug_ct!("post snippet is_content: {is_content}");

let rng = node.range();
Expand Down
Loading
Loading