Skip to content

Commit

Permalink
feat: update typst to 0ea6680
Browse files Browse the repository at this point in the history
feat: update typst to `0ea6680`

build: bump version to nightly 0.12.19 (Myriad-Dreamin#1261)
  • Loading branch information
ParaN3xus committed Feb 10, 2025
1 parent da2de02 commit c7f79b4
Show file tree
Hide file tree
Showing 34 changed files with 482 additions and 450 deletions.
728 changes: 383 additions & 345 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 14 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[workspace.package]
description = "An integrated language service for Typst."
authors = ["Myriad-Dreamin <[email protected]>", "Nathan Varner"]
version = "0.12.19-rc4"
version = "0.12.19"
edition = "2021"
readme = "README.md"
license = "Apache-2.0"
Expand Down Expand Up @@ -254,14 +254,14 @@ extend-exclude = ["/.git", "fixtures"]
# These patches use a different version of `typst`, which only exports some private functions and information for code analysis.
#
# A regular build MUST use `tag` or `rev` to specify the version of the patched crate to ensure stability.
typst = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-html = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-timing = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-svg = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-render = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-pdf = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-syntax = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst-eval = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.19-rc2-content-hint" }
typst = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.21-content-hint" }
typst-html = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.21-content-hint" }
typst-timing = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.21-content-hint" }
typst-svg = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.21-content-hint" }
typst-render = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.21-content-hint" }
typst-pdf = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.21-content-hint" }
typst-syntax = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.21-content-hint" }
typst-eval = { git = "https://github.com/ParaN3xus/typst.git", tag = "tinymist-nightly-v0.12.21-content-hint" }
typst-assets = { git = "https://github.com/typst/typst-assets", rev = "8cccef9" }

# These patches use local `typst` for development.
Expand All @@ -275,15 +275,16 @@ typst-assets = { git = "https://github.com/typst/typst-assets", rev = "8cccef9"
# These patches use a different version of `reflexo`.
#
# A regular build MUST use `tag` or `rev` to specify the version of the patched crate to ensure stability.
reflexo = { git = "https://github.com/Myriad-Dreamin/typst.ts/", rev = "cd9e2cab2acbee6e64dd1d91eecf6d98fb6b375c" }
reflexo-typst = { git = "https://github.com/Myriad-Dreamin/typst.ts/", rev = "cd9e2cab2acbee6e64dd1d91eecf6d98fb6b375c" }
reflexo-vec2svg = { git = "https://github.com/Myriad-Dreamin/typst.ts/", rev = "cd9e2cab2acbee6e64dd1d91eecf6d98fb6b375c" }
reflexo = { git = "https://github.com/ParaN3xus/typst.ts/", rev = "870e7c7b7f3df516482545b972f37dd0cee51800" }
reflexo-typst = { git = "https://github.com/ParaN3xus/typst.ts/", rev = "870e7c7b7f3df516482545b972f37dd0cee51800" }
reflexo-vec2svg = { git = "https://github.com/ParaN3xus/typst.ts/", rev = "870e7c7b7f3df516482545b972f37dd0cee51800" }

# These patches use local `reflexo` for development.
# reflexo = { path = "../typst.ts/crates/reflexo/" }
# reflexo-typst = { path = "../typst.ts/crates/reflexo-typst/" }
# reflexo-vec2svg = { path = "../typst.ts/crates/conversion/vec2svg/" }
typstyle-core = { git = "https://github.com/ParaN3xus/typstyle/", tag = "tinymist-nightly-v0.12.19-rc2" }

typstyle-core = { git = "https://github.com/ParaN3xus/typstyle/", rev = "a0f7aa658f13267c23aa9745b2c77ec114c0c3d0" }

[patch."https://github.com/Myriad-Dreamin/tinymist.git"]
typst-shim = { path = "crates/typst-shim" }
Expand Down
6 changes: 3 additions & 3 deletions crates/crityp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ pub fn bench(c: &mut Criterion, world: &mut LspWorld) -> anyhow::Result<()> {

// Collects all benchmarks.
let mut goals: Vec<(EcoString, &Func)> = vec![];
for (name, value, _) in module.scope().iter() {
for (name, bind) in module.scope().iter() {
if !name.starts_with("bench") {
continue;
}

if let Value::Func(func) = value {
goals.push((eco_format!("{main_path}@{name}"), func));
if let Value::Func(func) = bind.read() {
goals.push((eco_format!("{main_path}@{name}"), &func));
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/tinymist-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tinymist-web",
"version": "0.12.19-rc4",
"version": "0.12.19",
"description": "WASM module for running tinymist analyzers in JavaScript environment.",
"author": "Myriad-Dreamin",
"license": "Apache-2.0",
Expand Down
19 changes: 5 additions & 14 deletions crates/tinymist-query/src/analysis/completion/field_access.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ impl CompletionPair<'_, '_, '_> {
/// Add completions for all fields on a value.
fn value_field_access_completions(&mut self, target: &LinkedNode) -> Option<()> {
let (value, styles) = self.worker.ctx.analyze_expr(target).into_iter().next()?;
for (name, value, _) in value.ty().scope().iter() {
self.value_completion(Some(name.clone()), value, true, None);
for (name, bind) in value.ty().scope().iter() {
self.value_completion(Some(name.clone()), bind.read(), true, None);
}

if let Some(scope) = value.scope() {
for (name, value, _) in scope.iter() {
self.value_completion(Some(name.clone()), value, true, None);
for (name, bind) in scope.iter() {
self.value_completion(Some(name.clone()), bind.read(), true, None);
}
}

Expand All @@ -55,7 +55,7 @@ impl CompletionPair<'_, '_, '_> {
// this value's type, so accessing it should not fail.
self.value_completion(
Some(field.into()),
&value.field(field).unwrap(),
&value.field(field, ()).unwrap(),
false,
None,
);
Expand Down Expand Up @@ -108,15 +108,6 @@ impl CompletionPair<'_, '_, '_> {
}
}
}
Value::Plugin(plugin) => {
for name in plugin.iter() {
self.push_completion(Completion {
kind: CompletionKind::Func,
label: name.clone(),
..Completion::default()
})
}
}
_ => {}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/tinymist-query/src/analysis/completion/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ impl CompletionPair<'_, '_, '_> {
) {
// Select the source by `comps`
let value = self.worker.ctx.module_by_syntax(source);
let value = comps
.iter()
.fold(value.as_ref(), |value, comp| value?.scope()?.get(comp));
let value = comps.iter().fold(value.as_ref(), |value, comp| {
value?.scope()?.get(comp)?.read().into()
});
let Some(scope) = value.and_then(|v| v.scope()) else {
return;
};
Expand Down Expand Up @@ -125,9 +125,9 @@ impl CompletionPair<'_, '_, '_> {
self.snippet_completion("*", "*", "Import everything.");
}

for (name, value, _) in scope.iter() {
for (name, bind) in scope.iter() {
if seen.iter().all(|item| item.as_str() != name) {
self.value_completion(Some(name.clone()), value, false, None);
self.value_completion(Some(name.clone()), bind.read(), false, None);
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/tinymist-query/src/analysis/completion/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ impl FnCompletionFeat {
| Value::Dict(..)
| Value::Args(..)
| Value::Module(..)
| Value::Plugin(..)
| Value::Dyn(..) => {}
},
Ty::Func(sig) => self.check_sig(sig, pos),
Expand Down Expand Up @@ -263,7 +262,7 @@ fn fold_ty_kind<'a>(tys: impl Iterator<Item = &'a Ty>) -> CompletionKind {
pub(crate) fn value_to_completion_kind(value: &Value) -> CompletionKind {
match value {
Value::Func(..) => CompletionKind::Func,
Value::Plugin(..) | Value::Module(..) => CompletionKind::Module,
Value::Module(..) => CompletionKind::Module,
Value::Type(..) => CompletionKind::Type,
Value::Symbol(s) => CompletionKind::Symbol(s.get()),
Value::None
Expand Down
4 changes: 2 additions & 2 deletions crates/tinymist-query/src/analysis/completion/param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ impl CompletionPair<'_, '_, '_> {
let captures = visitor.finish();

// Converts the captures into completions.
for (name, value, _) in captures.iter() {
for (name, bind) in captures.iter() {
if !bindings.contains(name) {
let docs = "Parametrizes the captured variable.";
self.value_completion(Some(name.clone()), value, false, Some(docs));
self.value_completion(Some(name.clone()), bind.read(), false, Some(docs));
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/tinymist-query/src/analysis/completion/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ impl Defines {

pub fn insert_scope(&mut self, scope: &Scope) {
// filter(Some(value)) &&
for (name, value, _) in scope.iter() {
for (name, bind) in scope.iter() {
if !self.defines.contains_key(name) {
self.insert(name.clone(), Ty::Value(InsTy::new(value.clone())));
self.insert(name.clone(), Ty::Value(InsTy::new(bind.read().clone())));
}
}
}
Expand Down Expand Up @@ -301,8 +301,8 @@ impl CompletionScopeChecker<'_> {
for name in fields_on(ty) {
self.defines.insert((*name).into(), Ty::Any);
}
for (name, value, _) in ty.scope().iter() {
let ty = Ty::Value(InsTy::new(value.clone()));
for (name, bind) in ty.scope().iter() {
let ty = Ty::Value(InsTy::new(bind.read().clone()));
self.defines.insert(name.into(), ty);
}
}
Expand Down
16 changes: 12 additions & 4 deletions crates/tinymist-query/src/analysis/definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ pub fn resolve_call_target(ctx: &Arc<SharedContext>, node: &SyntaxNode) -> Optio
let field = access.field().get();
let values = ctx.analyze_expr(target.to_untyped());
if let Some((this, func_ptr)) = values.into_iter().find_map(|(this, _styles)| {
if let Some(Value::Func(func)) = this.ty().scope().get(field) {
if let Some(Value::Func(func)) = this.ty().scope().get(field).map(|b| b.read()) {
return Some((this, func.clone()));
}

Expand Down Expand Up @@ -288,15 +288,21 @@ fn is_same_native_func(x: Option<&Func>, y: &Func) -> bool {

static WITH_FUNC: LazyLock<Option<&'static Func>> = LazyLock::new(|| {
let fn_ty = Type::of::<Func>();
let Some(Value::Func(func)) = fn_ty.scope().get("with") else {
let Some(bind) = fn_ty.scope().get("with") else {
return None;
};
let Value::Func(func) = bind.read() else {
return None;
};
Some(func)
});

static WHERE_FUNC: LazyLock<Option<&'static Func>> = LazyLock::new(|| {
let fn_ty = Type::of::<Func>();
let Some(Value::Func(func)) = fn_ty.scope().get("where") else {
let Some(bind) = fn_ty.scope().get("where") else {
return None;
};
let Value::Func(func) = bind.read() else {
return None;
};
Some(func)
Expand All @@ -313,7 +319,9 @@ fn value_to_def(value: Value, name: impl FnOnce() -> Option<Interned<str>>) -> O
let decl = Decl::func(s.cast().unwrap());
Definition::new(decl.into(), Some(val))
}
Value::Module(module) => Definition::new_var(module.name().into(), val),
Value::Module(module) => {
Definition::new_var(Interned::new_str(module.name().unwrap()), val)
}
_v => Definition::new_var(name()?, val),
})
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tinymist-query/src/analysis/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ pub fn func_signature(func: Func) -> Signature {
analyze_closure_signature(closure.clone(), &mut add_param);
None
}
Repr::Element(..) | Repr::Native(..) => {
Repr::Element(..) | Repr::Native(..) | Repr::Plugin(..) => {
for param in func.params().unwrap() {
add_param(Interned::new(ParamTy {
name: param.name.into(),
Expand Down
11 changes: 1 addition & 10 deletions crates/tinymist-query/src/analysis/tyck/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ pub fn term_value(value: &Value) -> Ty {
}
// todo: term arguments
Value::Args(..) => Ty::Builtin(BuiltinTy::Args),
Value::Plugin(plugin) => {
// todo: create infer variables for plugin functions
let values = plugin
.iter()
.map(|method| (method.as_str().into(), Ty::Func(SigTy::any())))
.collect();
Ty::Dict(RecordTy::new(values))
}
Value::Dict(dict) => {
let values = dict
.iter()
Expand All @@ -63,7 +55,7 @@ pub fn term_value(value: &Value) -> Ty {
let values = module
.scope()
.iter()
.map(|(k, v, s)| (k.into(), term_value_rec(v, s)))
.map(|(k, b)| (k.into(), term_value_rec(b.read(), b.span())))
.collect();
Ty::Dict(RecordTy::new(values))
}
Expand All @@ -83,7 +75,6 @@ pub fn term_value_rec(value: &Value, s: Span) -> Ty {
| Value::Auto
| Value::Array(..)
| Value::Args(..)
| Value::Plugin(..)
| Value::Dict(..)
| Value::Module(..)
| Value::Func(..)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/math_ident_in_call.typ
"labelDetails": {
"description": "(content, size: relative) => content"
},
"sortText": "222",
"sortText": "229",
"textEdit": {
"newText": "norm(${1:})",
"range": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/math_ident_in_call2.ty
"labelDetails": {
"description": "(content, size: relative) => content"
},
"sortText": "224",
"sortText": "231",
"textEdit": {
"newText": "norm(${1:})",
"range": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/raw_lang.typ
{
"kind": 21,
"label": "Typst",
"sortText": "142",
"sortText": "145",
"textEdit": {
"newText": "typ",
"range": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/raw_lang_middle.typ
{
"kind": 21,
"label": "Typst",
"sortText": "142",
"sortText": "145",
"textEdit": {
"newText": "typ",
"range": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/raw_lang_middle_lower.
{
"kind": 21,
"label": "Typst",
"sortText": "142",
"sortText": "145",
"textEdit": {
"newText": "typ",
"range": {
Expand Down
2 changes: 1 addition & 1 deletion crates/tinymist-query/src/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl ExternalDocLink {
Repr::With(w) => {
func = &w.0;
}
Repr::Closure(..) => {
Repr::Closure(..) | Repr::Plugin(..) => {
return None;
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/tinymist-query/src/prepare_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ fn validate_fn_renaming(def: &Definition) -> Option<()> {
match func.inner() {
// todo: rename with site
Repr::With(w) => func = &w.0,
Repr::Closure(..) => return Some(()),
Repr::Closure(..) | Repr::Plugin(..) => return Some(()),
// native functions can't be renamed
Repr::Native(..) | Repr::Element(..) => return None,
}
Expand Down
12 changes: 8 additions & 4 deletions crates/tinymist-query/src/syntax/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ impl ExprScope {
// ref_expr.of = of.clone();
// ref_expr.val = val.map(|v| Ty::Value(InsTy::new(v.clone())));
// return ref_expr;
(of, val.cloned().map(|val| Ty::Value(InsTy::new(val))))
(
of,
val.cloned()
.map(|val| Ty::Value(InsTy::new(val.read().to_owned()))),
)
}

pub fn merge_into(&self, exports: &mut LexicalScope) {
Expand All @@ -150,23 +154,23 @@ impl ExprScope {
ExprScope::Module(module) => {
crate::log_debug_ct!("imported: {module:?}");
let v = Interned::new(Ty::Value(InsTy::new(Value::Module(module.clone()))));
for (name, _, _) in module.scope().iter() {
for (name, _) in module.scope().iter() {
let name: Interned<str> = name.into();
exports.insert_mut(name.clone(), select_of(v.clone(), name));
}
}
ExprScope::Func(func) => {
if let Some(scope) = func.scope() {
let v = Interned::new(Ty::Value(InsTy::new(Value::Func(func.clone()))));
for (name, _, _) in scope.iter() {
for (name, _) in scope.iter() {
let name: Interned<str> = name.into();
exports.insert_mut(name.clone(), select_of(v.clone(), name));
}
}
}
ExprScope::Type(ty) => {
let v = Interned::new(Ty::Value(InsTy::new(Value::Type(*ty))));
for (name, _, _) in ty.scope().iter() {
for (name, _) in ty.scope().iter() {
let name: Interned<str> = name.into();
exports.insert_mut(name.clone(), select_of(v.clone(), 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 @@ -287,7 +287,7 @@ impl DocsChecker<'_> {

let val = module.scope().get(name)?;
crate::log_debug_ct!("check doc type annotation: {name:?}");
if let Value::Content(raw) = val {
if let Value::Content(raw) = val.read() {
let annotated = raw.clone().unpack::<typst::text::RawElem>().ok()?;
let annotated = annotated.text.clone().into_value().cast::<Str>().ok()?;
let code = typst::syntax::parse_code(&annotated.as_str().replace('\'', "θ"));
Expand Down
Loading

0 comments on commit c7f79b4

Please sign in to comment.