feat: bump typst to v0.13.0-rc1 (#1342)

* dev: use range type from lsp-types

* feat: add html document variant

* feat: use new-style bytes constructors

* fix: broken span usages

* fix: syntax kind is changed

* fix: label use pico str

* fix: bib element is changed

* fix: raw element is changed

* fix: typst use codex

* fix: package fn is removed from world trait

* feat: reflexo accept typst document

* docs: update changelog

* dev: cargo patch

* fix: typst pdf timestamp is changed

* fix: pattern is renamed to tiling

* dev: make eval compat

* test: update snapshots

* build: bump version to nightly 0.12.19-rc4

* build: bump version to 0.12.19-rc1 (#1164)

  * build update changelog

  * build: bump version to 0.12.19-rc1

* build: bump version to nightly 0.12.19-rc2 (#1221)

  * feat: update typst to `85d1778`

  * deps: lock git deps version

  * build: bump version to 0.12.19-rc2

  * docs: remove rc in changelog

  * fix: mathtext formatting of typstyle

  * fix: completion related to mathtext

  * build: update cargo.lock

* build: bump version to nightly 0.12.19-rc3 (#1232)

* build: bump version to nightly 0.12.19-rc4 (#1239)

* feat: add typst-html

* feat: add typst-html

* cargo patch

* fix: features doesn't take effect

* fix: casting

* fix: broken no-content-hint

* fix: snapshot

* fix: remove unnecessary `fs` feature

* fix: move system features feature

* feat: remove nightly shim

* test: update snapshot

* dev: nightly v0.12.21 (#1279)

* feat: update typst to `0ea6680`

feat: update typst to `0ea6680`

build: bump version to nightly 0.12.19 (#1261)

* fix: fix lint errors

* styl: fotmat

* fix: build web ci

* build: update cargo.toml

* build: bump version to nightly 0.12.21-rc1 (#1280)

* build: update typstyle & reflexo (#1336)

* build: update typstyle & reflexo

* dev: remove useless patches

---------

Co-authored-by: Myriad-Dreamin <camiyoru@gmail.com>

* build: update version

* fix: pdf gate were broken (#1285)

* fix: panic on convert_datetime (#1286)

* feat: run language sever with targeting html (#1284)

* dev: add some debug logging

* feat: html compilation

* fix: revert changes

* feat: adjust html interfaces

* feat: lock reflexo

* feat: provide exportTarget configuration

* feat: export html actions when target is html

* build: bump reflexo

* fix: system feature gate

* fix: feature gate 2

* fix: feature gate 3

* feat: make tinymist-world featured by lsp

* feat: text export over typst's HTML export (#1289)

* feat: add more doc, world, and task apis (#1290)

* feat: add num of pages method

* feat: add from_snapshot_inner method

* feat: add clear_dedicates method

* feat: more convertion traits

* feat: add doc_get_as_value method

* feat: add doc_get_as_value method

* feat: add cast_run method

* fix: set is compiling flag (#1293)

* feat: publish {tinymist-{derive,analysis,std,vfs,world,project},typlite,crityp} crates (#1310)

* build: bump version to 0.12.21-pre-rc1

* fix: deps

* build: set nightly in nightly branch

* docs: add readmes for publish

* feat: add release crates action

* dev: remove publish of sync-lsp

* dev: remove useless setup

* fix: remove readme

* fix: publish ignore errors

* fix: specify version for publish

* fix: specify version for publish

* feat: update tinymist-web version

* test: update snapshot

* fix: diverged deps

---------

Co-authored-by: ParaN3xus <136563585+ParaN3xus@users.noreply.github.com>
This commit is contained in:
Myriad-Dreamin 2025-02-21 03:18:04 +08:00 committed by GitHub
parent 0260bfb527
commit d21ebc38dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
137 changed files with 1722 additions and 1156 deletions

View file

@ -56,7 +56,7 @@ triomphe.workspace = true
base64.workspace = true
typlite.workspace = true
tinymist-world = { workspace = true }
tinymist-project = { workspace = true, features = ["system"] }
tinymist-project = { workspace = true, features = ["lsp"] }
tinymist-analysis.workspace = true
tinymist-derive.workspace = true
tinymist-std.workspace = true
@ -71,7 +71,6 @@ sha2 = { version = "0.10" }
hex = { version = "0.4" }
[features]
no-content-hint = ["tinymist-project/no-content-hint"]
[lints]
workspace = true

View file

@ -358,7 +358,7 @@ mod type_check_tests {
.map(|bounds| (bounds.name(), bounds))
.collect::<Vec<_>>();
vars.sort_by(|x, y| x.1.var.cmp(&y.1.var));
vars.sort_by(|x, y| x.1.var.strict_cmp(&y.1.var));
for (name, bounds) in vars {
writeln!(f, "{name:?} = {:?}", info.simplify(bounds.as_type(), true))?;
@ -590,7 +590,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)?;

View file

@ -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);
}
}
@ -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,
);
@ -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()
})
}
}
_ => {}
}

View file

@ -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;
};
@ -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);
}
}
}

View file

@ -114,7 +114,7 @@ impl FnCompletionFeat {
| Value::Fraction(..)
| Value::Color(..)
| Value::Gradient(..)
| Value::Pattern(..)
| Value::Tiling(..)
| Value::Symbol(..)
| Value::Version(..)
| Value::Str(..)
@ -129,7 +129,6 @@ impl FnCompletionFeat {
| Value::Dict(..)
| Value::Args(..)
| Value::Module(..)
| Value::Plugin(..)
| Value::Dyn(..) => {}
},
Ty::Func(sig) => self.check_sig(sig, pos),
@ -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
@ -278,7 +277,7 @@ pub(crate) fn value_to_completion_kind(value: &Value) -> CompletionKind {
| Value::Fraction(..)
| Value::Color(..)
| Value::Gradient(..)
| Value::Pattern(..)
| Value::Tiling(..)
| Value::Version(..)
| Value::Str(..)
| Value::Bytes(..)

View file

@ -120,7 +120,7 @@ impl CompletionPair<'_, '_, '_> {
if !is_triggered_by_punc(self.worker.trigger_character)
&& matches!(
self.cursor.leaf.kind(),
SyntaxKind::Text | SyntaxKind::MathIdent
SyntaxKind::Text | SyntaxKind::MathIdent | SyntaxKind::MathText
)
{
self.cursor.from = self.cursor.leaf.offset();

View file

@ -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));
}
}

View file

@ -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())));
}
}
}
@ -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);
}
}

View file

@ -113,7 +113,7 @@ impl CompletionPair<'_, '_, '_> {
if !self.worker.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!(

View file

@ -144,7 +144,7 @@ fn bib_definition(
key: &str,
) -> Option<Definition> {
let bib_elem = BibliographyElem::find(introspector.track()).ok()?;
let Value::Array(paths) = bib_elem.path().clone().into_value() else {
let Value::Array(paths) = bib_elem.sources.clone().into_value() else {
return None;
};
@ -164,7 +164,7 @@ fn ref_definition(
name: &str,
ref_expr: ast::Expr,
) -> Option<Definition> {
let label = Label::new(name);
let label = Label::construct(name.into());
let sel = Selector::Label(label);
// if it is a label, we put the selection range to itself
@ -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()));
}
@ -288,7 +288,8 @@ 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 bind = fn_ty.scope().get("with")?;
let Value::Func(func) = bind.read() else {
return None;
};
Some(func)
@ -296,7 +297,8 @@ static WITH_FUNC: LazyLock<Option<&'static Func>> = LazyLock::new(|| {
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 bind = fn_ty.scope().get("where")?;
let Value::Func(func) = bind.read() else {
return None;
};
Some(func)
@ -313,7 +315,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),
})
}

View file

@ -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(),

View file

@ -2,14 +2,14 @@
use comemo::Track;
use ecow::*;
use tinymist_std::typst::TypstDocument;
use tinymist_std::typst::{TypstDocument, TypstPagedDocument};
use typst::engine::{Engine, Route, Sink, Traced};
use typst::eval::Vm;
use typst::foundations::{Context, Label, Scopes, Styles, Value};
use typst::introspection::Introspector;
use typst::model::BibliographyElem;
use typst::syntax::{ast, LinkedNode, Span, SyntaxKind, SyntaxNode};
use typst::World;
use typst_shim::eval::Vm;
/// Try to determine a set of possible values for an expression.
pub fn analyze_expr(world: &dyn World, node: &LinkedNode) -> EcoVec<(Value, Option<Styles>)> {
@ -43,7 +43,7 @@ pub fn analyze_expr_(world: &dyn World, node: &SyntaxNode) -> EcoVec<(Value, Opt
}
}
return typst::trace(world, node.span());
return typst::trace::<TypstPagedDocument>(world, node.span());
}
};
@ -64,6 +64,7 @@ pub fn analyze_import_(world: &dyn World, source: &SyntaxNode) -> (Option<Value>
let traced = Traced::default();
let mut sink = Sink::new();
let engine = Engine {
routines: &typst::ROUTINES,
world: world.track(),
route: Route::default(),
introspector: introspector.track(),
@ -78,9 +79,13 @@ pub fn analyze_import_(world: &dyn World, source: &SyntaxNode) -> (Option<Value>
Scopes::new(Some(world.library())),
Span::detached(),
);
let module = typst_shim::eval::import(&mut vm, source.clone(), source_span, true)
.ok()
.map(Value::Module);
let module = match source.clone() {
Value::Str(path) => typst_shim::eval::import(&mut vm.engine, &path, source_span)
.ok()
.map(Value::Module),
Value::Module(module) => Some(Value::Module(module)),
_ => None,
};
(Some(source), module)
}
@ -137,9 +142,9 @@ pub fn analyze_labels(document: &TypstDocument) -> (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,

View file

@ -19,7 +19,7 @@ pub fn is_plain_value(value: &Value) -> bool {
| Value::Fraction(..)
| Value::Color(..)
| Value::Gradient(..)
| Value::Pattern(..)
| Value::Tiling(..)
| Value::Symbol(..)
| Value::Version(..)
| Value::Str(..)
@ -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()
@ -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))
}
@ -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(..)
@ -99,7 +90,7 @@ pub fn term_value_rec(value: &Value, s: Span) -> Ty {
| Value::Fraction(..)
| Value::Color(..)
| Value::Gradient(..)
| Value::Pattern(..)
| Value::Tiling(..)
| Value::Symbol(..)
| Value::Version(..)
| Value::Str(..)

View file

@ -104,7 +104,7 @@ impl SemanticRequest for InteractCodeContextRequest {
let _ = world.map_shadow_by_id(
mapped_source.id(),
Bytes::from(mapped_source.text().as_bytes()),
Bytes::new(mapped_source.text().as_bytes().to_vec()),
);
world.take_db();
@ -130,7 +130,7 @@ impl SemanticRequest for InteractCodeContextRequest {
.collect();
let _ = world.map_shadow_by_id(
mapped_source.id(),
Bytes::from(source.text().as_bytes()),
Bytes::new(source.text().as_bytes().to_vec()),
);
Some(InteractCodeContextResponse::StyleAt { style })

View file

@ -33,7 +33,15 @@ impl SemanticRequest for CodeLensRequest {
res.push(doc_lens("Profile", vec!["profile".into()]));
res.push(doc_lens("Preview", vec!["preview".into()]));
res.push(doc_lens("Export PDF", vec!["export-pdf".into()]));
let is_html = ctx.world.library.features.is_enabled(typst::Feature::Html);
if is_html {
res.push(doc_lens("Export HTML", vec!["export-html".into()]));
} else {
res.push(doc_lens("Export PDF", vec!["export-pdf".into()]));
}
res.push(doc_lens("More ..", vec!["more".into()]));
Some(res)

View file

@ -23,7 +23,7 @@ pub(crate) fn convert_docs(ctx: &SharedContext, content: &str) -> StrResult<EcoS
entry: Some(entry),
inputs: None,
});
w.map_shadow_by_id(w.main(), Bytes::from(content.as_bytes().to_owned()))?;
w.map_shadow_by_id(w.main(), Bytes::from_string(content.to_owned()))?;
// todo: bad performance
w.take_db();

View file

@ -151,6 +151,7 @@ impl DocumentMetricsWorker<'_> {
Some(())
}
_ => None,
}
}

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on t (63..64)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/bracket_strong.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(content, delta: int) => strong"
},
"sortText": "180",
"sortText": "182",
"textEdit": {
"newText": "strong(${1:})",
"range": {
@ -36,7 +35,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(content, delta: int) => strong"
},
"sortText": "181",
"sortText": "183",
"textEdit": {
"newText": "strong[${1:}]",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on ( (71..72)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/builtin_shadow.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(fill-rest: false) => none"
},
"sortText": "126",
"sortText": "127",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on ( (70..71)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/builtin_shadow_existing.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(fill-rest: false) => none"
},
"sortText": "127",
"sortText": "128",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on (23..24)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/colon_markup.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(content, b: content | none, bl: content | none, br: content | none, t: content | none, tl: content | none, tr: content | none) => attach"
},
"sortText": "075",
"sortText": "076",
"textEdit": {
"newText": " attach(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on (23..24)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/colon_math.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(content, b: content | none, bl: content | none, br: content | none, t: content | none, tl: content | none, tr: content | none) => attach"
},
"sortText": "075",
"sortText": "076",
"textEdit": {
"newText": " attach(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (36..37)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/context_code_init.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"sortText": "127",
"sortText": "128",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (34..35)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/context_init.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"sortText": "127",
"sortText": "128",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (26..27)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/hash.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"sortText": "126",
"sortText": "127",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (28..29)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/hash_ident.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"sortText": "126",
"sortText": "127",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (28..29)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/hash_math.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"sortText": "126",
"sortText": "127",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (30..31)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/hash_math_ident.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"sortText": "126",
"sortText": "127",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (40..41)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/let_closure_init.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"sortText": "128",
"sortText": "129",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (37..38)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/let_fn_init.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"sortText": "128",
"sortText": "129",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (34..35)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/let_init.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(to: \"even\" | \"odd\" | none, weak: bool) => pagebreak"
},
"sortText": "128",
"sortText": "129",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (30..31)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/math_bold2.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(content) => content"
},
"sortText": "086",
"sortText": "087",
"textEdit": {
"newText": "bold(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (28..29)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call.typ
snapshot_kind: text
---
[
{
@ -31,7 +30,7 @@ snapshot_kind: text
"kind": 3,
"label": "abs",
"labelDetails": {
"description": "(content, size: auto | relative) => content"
"description": "(content, size: relative) => content"
},
"sortText": "058",
"textEdit": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (27..28)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call2.typ
snapshot_kind: text
---
[
{
@ -13,7 +12,7 @@ snapshot_kind: text
"kind": 3,
"label": "abs",
"labelDetails": {
"description": "(content, size: auto | relative) => content"
"description": "(content, size: relative) => content"
},
"sortText": "057",
"textEdit": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (28..29)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call3.typ
snapshot_kind: text
---
[
{
@ -13,7 +12,7 @@ snapshot_kind: text
"kind": 3,
"label": "abs",
"labelDetails": {
"description": "(content, size: auto | relative) => content"
"description": "(content, size: relative) => content"
},
"sortText": "055",
"textEdit": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (29..30)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/math_call_in_call4.typ
snapshot_kind: text
---
[
{
@ -13,7 +12,7 @@ snapshot_kind: text
"kind": 3,
"label": "abs",
"labelDetails": {
"description": "(content, size: auto | relative) => content"
"description": "(content, size: relative) => content"
},
"sortText": "055",
"textEdit": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (27..28)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/math_ident_in_call.typ
snapshot_kind: text
---
[
{
@ -13,9 +12,9 @@ snapshot_kind: text
"kind": 3,
"label": "norm",
"labelDetails": {
"description": "(content, size: auto | relative) => content"
"description": "(content, size: relative) => content"
},
"sortText": "221",
"sortText": "229",
"textEdit": {
"newText": "norm(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (28..29)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/math_ident_in_call2.typ
snapshot_kind: text
---
[
{
@ -13,9 +12,9 @@ snapshot_kind: text
"kind": 3,
"label": "norm",
"labelDetails": {
"description": "(content, size: auto | relative) => content"
"description": "(content, size: relative) => content"
},
"sortText": "223",
"sortText": "231",
"textEdit": {
"newText": "norm(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (92..93)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/set.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "052",
"sortText": "053",
"textEdit": {
"newText": "raw(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (86..87)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/set2.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "052",
"sortText": "053",
"textEdit": {
"newText": "raw(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (114..115)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/set_in_show.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "053",
"sortText": "054",
"textEdit": {
"newText": "raw(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (109..110)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/show.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "094",
"sortText": "096",
"textEdit": {
"newText": "raw: ${1:}",
"range": {
@ -36,7 +35,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "095",
"sortText": "097",
"textEdit": {
"newText": "raw.where(${1:}): ${2:}",
"range": {
@ -54,7 +53,7 @@ snapshot_kind: text
{
"kind": 15,
"label": "regex selector",
"sortText": "100",
"sortText": "102",
"textEdit": {
"newText": "regex(\"${1:regex}\"): ${2:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (108..109)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/show2.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "094",
"sortText": "096",
"textEdit": {
"newText": "raw: ${1:}",
"range": {
@ -36,7 +35,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "095",
"sortText": "097",
"textEdit": {
"newText": "raw.where(${1:}): ${2:}",
"range": {
@ -54,7 +53,7 @@ snapshot_kind: text
{
"kind": 15,
"label": "regex selector",
"sortText": "100",
"sortText": "102",
"textEdit": {
"newText": "regex(\"${1:regex}\"): ${2:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (103..104)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/show3.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "094",
"sortText": "096",
"textEdit": {
"newText": "raw: ${1:}",
"range": {
@ -36,7 +35,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "095",
"sortText": "097",
"textEdit": {
"newText": "raw.where(${1:}): ${2:}",
"range": {
@ -54,7 +53,7 @@ snapshot_kind: text
{
"kind": 15,
"label": "regex selector",
"sortText": "100",
"sortText": "102",
"textEdit": {
"newText": "regex(\"${1:regex}\"): ${2:}",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (93..94)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "173",
"sortText": "175",
"textEdit": {
"newText": "raw(${1:})",
"range": {
@ -36,7 +35,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "174",
"sortText": "176",
"textEdit": {
"newText": "raw.with(${1:})",
"range": {
@ -57,7 +56,7 @@ snapshot_kind: text
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "175",
"sortText": "177",
"textEdit": {
"newText": "read(${1:})",
"range": {
@ -78,7 +77,7 @@ snapshot_kind: text
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "176",
"sortText": "178",
"textEdit": {
"newText": "read.with(${1:})",
"range": {
@ -96,7 +95,7 @@ snapshot_kind: text
{
"kind": 15,
"label": "replacement",
"sortText": "187",
"sortText": "189",
"textEdit": {
"newText": "[${1:content}]",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (92..93)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "173",
"sortText": "175",
"textEdit": {
"newText": "raw(${1:})",
"range": {
@ -36,7 +35,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "174",
"sortText": "176",
"textEdit": {
"newText": "raw.with(${1:})",
"range": {
@ -57,7 +56,7 @@ snapshot_kind: text
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "175",
"sortText": "177",
"textEdit": {
"newText": "read(${1:})",
"range": {
@ -78,7 +77,7 @@ snapshot_kind: text
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "176",
"sortText": "178",
"textEdit": {
"newText": "read.with(${1:})",
"range": {
@ -96,7 +95,7 @@ snapshot_kind: text
{
"kind": 15,
"label": "replacement",
"sortText": "187",
"sortText": "189",
"textEdit": {
"newText": "[${1:content}]",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (91..92)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
snapshot_kind: text
---
[
{
@ -15,7 +14,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "173",
"sortText": "175",
"textEdit": {
"newText": " raw(${1:})",
"range": {
@ -36,7 +35,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "174",
"sortText": "176",
"textEdit": {
"newText": " raw.with(${1:})",
"range": {
@ -57,7 +56,7 @@ snapshot_kind: text
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "175",
"sortText": "177",
"textEdit": {
"newText": " read(${1:})",
"range": {
@ -78,7 +77,7 @@ snapshot_kind: text
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "176",
"sortText": "178",
"textEdit": {
"newText": " read.with(${1:})",
"range": {
@ -96,7 +95,7 @@ snapshot_kind: text
{
"kind": 15,
"label": "replacement",
"sortText": "187",
"sortText": "189",
"textEdit": {
"newText": " [${1:content}]",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (57..58)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-core-slides.typ
snapshot_kind: text
---
[
{
@ -57,7 +56,7 @@ snapshot_kind: text
"labelDetails": {
"description": "(content, gap: length, justify: bool) => repeat"
},
"sortText": "159",
"sortText": "161",
"textEdit": {
"newText": "repeat(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (71..72)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-cover-with-rect.typ
snapshot_kind: text
---
[
{
@ -36,7 +35,7 @@ snapshot_kind: text
"labelDetails": {
"description": "type"
},
"sortText": "186",
"sortText": "188",
"textEdit": {
"newText": "stroke(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (63..64)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-current-heading.typ
snapshot_kind: text
---
[
{
@ -33,7 +32,7 @@ snapshot_kind: text
"labelDetails": {
"description": "type"
},
"sortText": "089",
"sortText": "090",
"textEdit": {
"newText": "int(${1:})",
"range": {

View file

@ -3,7 +3,6 @@ source: crates/tinymist-query/src/completion.rs
description: Completion on / (71..72)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-markup-text.typ
snapshot_kind: text
---
[
{
@ -69,7 +68,7 @@ snapshot_kind: text
"labelDetails": {
"description": "type"
},
"sortText": "180",
"sortText": "182",
"textEdit": {
"newText": "str(${1:})",
"range": {

View file

@ -2,6 +2,5 @@
source: crates/tinymist-query/src/semantic_tokens_full.rs
expression: "serde_json::to_string(&result).unwrap()"
input_file: crates/tinymist-query/src/fixtures/semantic_tokens/tinymist_issue_601.typ
snapshot_kind: text
---
{"data":[0,0,1,21,4,0,1,3,5,4,0,3,1,10,4,0,1,1,22,4,0,1,1,3,4,0,1,1,22,4,0,1,1,22,4,1,0,1,22,4,0,1,1,22,4,1,0,1,22,4]}
{"data":[0,0,1,21,4,0,1,3,5,4,0,3,1,21,4,0,1,1,22,4,0,1,1,3,4,0,1,1,22,4,0,1,1,22,4,1,0,1,22,4,0,1,1,22,0,1,0,1,22,0]}

View file

@ -325,7 +325,7 @@ impl ExternalDocLink {
Repr::With(w) => {
func = &w.0;
}
Repr::Closure(..) => {
Repr::Closure(..) | Repr::Plugin(..) => {
return None;
}
}

View file

@ -49,6 +49,7 @@ pub fn jump_from_cursor(
point,
})
}
_ => None,
}
}
@ -68,7 +69,12 @@ fn find_in_frame(frame: &Frame, span: Span, min_dis: &mut u64, res: &mut Point)
return Some(pos);
}
if glyph.span.0.id() == span.id() {
let dis = glyph.span.0.number().abs_diff(span.number());
let dis = glyph
.span
.0
.into_raw()
.get()
.abs_diff(span.into_raw().get());
if dis < *min_dis {
*min_dis = dis;
*res = pos;

View file

@ -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,
}

View file

@ -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) {
@ -150,7 +154,7 @@ 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));
}
@ -158,7 +162,7 @@ impl ExprScope {
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));
}
@ -166,7 +170,7 @@ impl ExprScope {
}
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));
}
@ -460,13 +464,62 @@ 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()))
}
}
trait StrictCmp {
/// Low-performance comparison but it is free from the concurrency issue.
/// This is only used for making stable test snapshots.
fn strict_cmp(&self, other: &Self) -> std::cmp::Ordering;
}
impl Decl {
pub fn strict_cmp(&self, other: &Self) -> std::cmp::Ordering {
let base = match (self, other) {
(Self::Generated(l), Self::Generated(r)) => l.0 .0.cmp(&r.0 .0),
(Self::Module(l), Self::Module(r)) => l.fid.strict_cmp(&r.fid),
(Self::Docs(l), Self::Docs(r)) => l
.var
.strict_cmp(&r.var)
.then_with(|| l.base.strict_cmp(&r.base)),
_ => self.span().strict_cmp(&other.span()),
};
base.then_with(|| self.name().cmp(other.name()))
}
}
impl StrictCmp for TypstFileId {
fn strict_cmp(&self, other: &Self) -> std::cmp::Ordering {
self.package()
.map(ToString::to_string)
.cmp(&other.package().map(ToString::to_string))
.then_with(|| self.vpath().cmp(other.vpath()))
}
}
impl<T: StrictCmp> StrictCmp for Option<T> {
fn strict_cmp(&self, other: &Self) -> std::cmp::Ordering {
match (self, other) {
(Some(l), Some(r)) => l.strict_cmp(r),
(Some(_), None) => std::cmp::Ordering::Greater,
(None, Some(_)) => std::cmp::Ordering::Less,
(None, None) => std::cmp::Ordering::Equal,
}
}
}
impl StrictCmp for Span {
fn strict_cmp(&self, other: &Self) -> std::cmp::Ordering {
self.id()
.strict_cmp(&other.id())
.then_with(|| self.into_raw().cmp(&other.into_raw()))
}
}
impl PartialOrd for Decl {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))

View file

@ -239,8 +239,8 @@ impl DocsChecker<'_> {
.chain([
Type::of::<typst::visualize::Color>(),
Type::of::<typst::visualize::Gradient>(),
Type::of::<typst::visualize::Pattern>(),
Type::of::<typst::symbols::Symbol>(),
Type::of::<typst::visualize::Tiling>(),
Type::of::<typst::foundations::Symbol>(),
Type::of::<typst::foundations::Version>(),
Type::of::<typst::foundations::Bytes>(),
Type::of::<typst::foundations::Label>(),
@ -287,9 +287,9 @@ 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 annotated = annotated.text.clone().into_value().cast::<Str>().ok()?;
let code = typst::syntax::parse_code(&annotated.as_str().replace('\'', "θ"));
let mut exprs = code.cast::<ast::Code>()?.exprs();
let term = self.check_type_expr(module, exprs.next()?);

View file

@ -8,7 +8,7 @@ use tinymist_std::hash::hash128;
use typst::{
foundations::{Element, NativeElement, Value},
model::{EmphElem, EnumElem, HeadingElem, ListElem, StrongElem, TermsElem},
syntax::{Span, SyntaxNode},
syntax::{ast::MathTextKind, Span, SyntaxNode},
utils::LazyHash,
};
@ -424,6 +424,12 @@ impl ExprWorker<'_> {
self.check_math([num, denom].iter())
}
MathRoot(root) => self.check(root.radicand()),
MathText(mathtext) => {
Expr::Type(Ty::Value(InsTy::new(Value::Str(match mathtext.get() {
MathTextKind::Character(c) => c.into(),
MathTextKind::Number(n) => n.to_string().into(),
}))))
}
}
}
@ -742,7 +748,9 @@ impl ExprWorker<'_> {
(_, Some(Value::Module(m))) => {
// todo: dyn resolve src_expr
match m.file_id() {
Some(fid) => Some(Expr::Decl(Decl::module(m.name().into(), fid).into())),
Some(fid) => Some(Expr::Decl(
Decl::module(m.name().unwrap().into(), fid).into(),
)),
None => Some(Expr::Type(Ty::Value(InsTy::new(Value::Module(m))))),
}
}
@ -1162,7 +1170,7 @@ impl ExprWorker<'_> {
// v.select(field.name()).ok()
match v {
Ty::Value(val) => {
Some(Ty::Value(InsTy::new(val.val.field(field.name()).ok()?)))
Some(Ty::Value(InsTy::new(val.val.field(field.name(), ()).ok()?)))
}
_ => None,
}
@ -1202,7 +1210,7 @@ impl ExprWorker<'_> {
let val = scope
.get(name)
.cloned()
.map(|val| Ty::Value(InsTy::new(val)));
.map(|val| Ty::Value(InsTy::new(val.read().clone())));
(None, val)
}

View file

@ -10,7 +10,7 @@ use std::{
use once_cell::sync::Lazy;
use serde_json::{ser::PrettyFormatter, Serializer, Value};
use tinymist_project::CompileFontArgs;
use tinymist_project::{CompileFontArgs, ExportTarget};
use tinymist_std::typst::TypstDocument;
use tinymist_world::package::PackageSpec;
use tinymist_world::vfs::WorkspaceResolver;
@ -155,6 +155,7 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
};
let mut verse = LspUniverseBuilder::build(
EntryState::new_rooted(root.as_path().into(), None),
ExportTarget::Paged,
Default::default(),
Arc::new(
LspUniverseBuilder::resolve_fonts(CompileFontArgs {
@ -187,7 +188,7 @@ pub fn run_with_sources<T>(source: &str, f: impl FnOnce(&mut LspUniverse, PathBu
let pw = root.join(Path::new(&path));
verse
.map_shadow(&pw, Bytes::from(source.as_bytes()))
.map_shadow(&pw, Bytes::from_string(source.to_owned()))
.unwrap();
last_pw = Some(pw);
}

View file

@ -121,7 +121,7 @@ impl Ty {
pub(crate) fn from_param_site(func: &Func, param: &ParamInfo) -> Ty {
use typst::foundations::func::Repr;
match func.inner() {
Repr::Element(..) | Repr::Native(..) => {
Repr::Element(..) | Repr::Native(..) | Repr::Plugin(..) => {
if let Some(ty) = param_mapping(func, param) {
return ty;
}
@ -137,7 +137,7 @@ impl Ty {
use typst::foundations::func::Repr;
match func.inner() {
Repr::Element(elem) => return Ty::Builtin(BuiltinTy::Element(*elem)),
Repr::Closure(_) => {}
Repr::Closure(_) | Repr::Plugin(_) => {}
Repr::With(w) => return Ty::from_return_site(&w.0, ty),
Repr::Native(_) => {}
};

View file

@ -183,7 +183,7 @@ impl Ty {
Ty::Builtin(BuiltinTy::Module(m)) => m.name().clone(),
ty => ty
.value()
.and_then(|v| Some(Interned::new_str(v.name()?)))
.map(|_| Interned::new_str(&self.name()))
.unwrap_or_default(),
}
}
@ -253,7 +253,7 @@ impl Ty {
}
fn is_content_builtin_type(ty: &Type) -> bool {
*ty == Type::of::<Content>() || *ty == Type::of::<typst::symbols::Symbol>()
*ty == Type::of::<Content>() || *ty == Type::of::<typst::foundations::Symbol>()
}
/// A function parameter type
@ -646,6 +646,14 @@ impl Ord for TypeVar {
}
}
impl TypeVar {
/// Low-performance comparison but it is free from the concurrency issue.
/// This is only used for making stable test snapshots.
pub fn strict_cmp(&self, other: &Self) -> std::cmp::Ordering {
self.def.strict_cmp(&other.def)
}
}
impl PartialOrd for TypeVar {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))

View file

@ -196,7 +196,7 @@ impl TypeDescriber {
let Value::Module(m) = &v.val else {
return "module".into();
};
return eco_format!("module({})", m.name());
return eco_format!("module({})", m.name().unwrap());
}
Ty::Value(v) if !is_plain_value(&v.val) => return self.describe(&term_value(&v.val)),
Ty::Value(v) if self.value => return truncated_repr_::<181>(&v.val),

View file

@ -1,8 +1,5 @@
use typst::foundations::{Dict, Module, Scope, Type};
use typst::syntax::FileId;
use typst::{
foundations::{Dict, Module, Scope, Type},
syntax::Span,
};
use super::BoundChecker;
use crate::{syntax::Decl, ty::prelude::*};
@ -56,8 +53,8 @@ impl Iface<'_> {
fn select_scope(scope: Option<&Scope>, key: &str) -> Option<Ty> {
let scope = scope?;
let sub = scope.get(key)?;
let sub_span = scope.get_span(key).unwrap_or_else(Span::detached);
Some(Ty::Value(InsTy::new_at(sub.clone(), sub_span)))
let sub_span = sub.span();
Some(Ty::Value(InsTy::new_at(sub.read().clone(), sub_span)))
}
pub trait IfaceChecker: TyCtx {

View file

@ -7,7 +7,7 @@ use serde::Deserialize;
use serde_yaml as yaml;
use typst::{
diag::{bail, StrResult},
foundations::{Content, Func, Module, Type, Value},
foundations::{Binding, Content, Func, Module, Type, Value},
introspection::MetadataElem,
syntax::Span,
text::{FontInfo, FontStyle},
@ -113,8 +113,8 @@ static GROUPS: Lazy<Vec<GroupData>> = Lazy::new(|| {
.module()
.scope()
.iter()
.filter(|(_, v, _)| matches!(v, Value::Func(_)))
.map(|(k, _, _)| k.clone())
.filter(|(_, v)| matches!(v.read(), Value::Func(_)))
.map(|(k, _)| k.clone())
.collect();
}
}
@ -175,7 +175,7 @@ static LIBRARY: Lazy<Library> = Lazy::new(Library::default);
/// Extract a module from another module.
#[track_caller]
fn get_module<'a>(parent: &'a Module, name: &str) -> StrResult<&'a Module> {
match parent.scope().get(name) {
match parent.scope().get(name).map(|x| x.read()) {
Some(Value::Module(module)) => Ok(module),
_ => bail!("module doesn't contain module `{name}`"),
}
@ -189,7 +189,7 @@ fn resolve_definition(head: &str, base: &str) -> StrResult<String> {
while let Some(name) = parts.peek() {
if category.is_none() {
category = focus.scope().get_category(name);
category = focus.scope().get(name).and_then(Binding::category);
}
let Ok(module) = get_module(focus, name) else {
break;
@ -203,7 +203,7 @@ fn resolve_definition(head: &str, base: &str) -> StrResult<String> {
};
let name = parts.next().ok_or("link is missing first part")?;
let value = focus.field(name)?;
let value = focus.field(name, ())?;
// Handle grouped functions.
if let Some(group) = GROUPS.iter().find(|group| {
@ -222,7 +222,7 @@ fn resolve_definition(head: &str, base: &str) -> StrResult<String> {
let mut route = format!("{}reference/{}/{name}", base, category.name());
if let Some(next) = parts.next() {
if let Ok(field) = value.field(next) {
if let Ok(field) = value.field(next, ()) {
route.push_str("/#definitions-");
route.push_str(next);
if let Some(next) = parts.next() {
@ -283,10 +283,10 @@ static ROUTE_MAPS: Lazy<HashMap<CatKey, String>> = Lazy::new(|| {
(LIBRARY.math.scope(), None, None),
];
while let Some((scope, parent_name, cat)) = scope_to_finds.pop() {
for (name, value, _) in scope.iter() {
let cat = cat.or_else(|| scope.get_category(name));
for (name, bind) in scope.iter() {
let cat = cat.or_else(|| bind.category());
let name = urlify(name);
match value {
match bind.read() {
Value::Func(func) => {
if let Some(cat) = cat {
let Some(name) = func.name() else {
@ -437,6 +437,7 @@ pub fn with_vm<T>(
let traced = Traced::default();
let mut sink = Sink::new();
let engine = Engine {
routines: &typst::ROUTINES,
world,
route: Route::default(),
introspector: introspector.track(),

View file

@ -148,7 +148,7 @@ fn closure_tooltip(leaf: &LinkedNode) -> Option<Tooltip> {
let captures = visitor.finish();
let mut names: Vec<_> = captures
.iter()
.map(|(name, _, _)| eco_format!("`{name}`"))
.map(|(name, _)| eco_format!("`{name}`"))
.collect();
if names.is_empty() {
return None;
@ -193,7 +193,7 @@ fn named_param_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option<Tooltip>
};
// Find metadata about the function.
if let Some(Value::Func(func)) = world.library().global.scope().get(&callee);
if let Some(Value::Func(func)) = world.library().global.scope().get(&callee).map(|x| x.read());
then { (func, named) }
else { return None; }
};