feat: complete std which isn't in any builtin scopes (#1483)

* feat: complete `std` which isn't in any builtin scopes

* test: update snapshot

* test: update snapshot

* test: update snapshot
This commit is contained in:
Myriad-Dreamin 2025-03-10 23:03:43 +08:00 committed by GitHub
parent be9c0478f6
commit e8507fea96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 71 additions and 8 deletions

View file

@ -98,6 +98,11 @@ impl CompletionPair<'_, '_, '_> {
.clone();
defines.insert_scope(&scope);
defines.insert(
EcoString::inline("std"),
Ty::Value(InsTy::new(lib.std.read().clone())),
);
Some(defines)
}

View file

@ -0,0 +1,2 @@
/// contains: std
#show raw: s/* range 0..1 */

View file

@ -0,0 +1,2 @@
/// contains: std
#s/* range 0..1 */

View file

@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/bracket_strong.typ
"labelDetails": {
"description": "(content, delta: int) => strong"
},
"sortText": "182",
"sortText": "183",
"textEdit": {
"newText": "strong(${1:})",
"range": {
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/bracket_strong.typ
"labelDetails": {
"description": "(content, delta: int) => strong"
},
"sortText": "183",
"sortText": "184",
"textEdit": {
"newText": "strong[${1:}]",
"range": {

View file

@ -0,0 +1,12 @@
---
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/module_show.typ
---
[
{
"isIncomplete": false,
"items": []
}
]

View file

@ -0,0 +1,34 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on / (20..21)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/module_std.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 9,
"label": "std",
"labelDetails": {
"description": "module(\"global\")"
},
"sortText": "177",
"textEdit": {
"newText": "std",
"range": {
"end": {
"character": 2,
"line": 1
},
"start": {
"character": 1,
"line": 1
}
}
}
}
]
}
]

View file

@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-cover-with-rec
"labelDetails": {
"description": "type"
},
"sortText": "185",
"sortText": "186",
"textEdit": {
"newText": "stroke(${1:})",
"range": {

View file

@ -68,7 +68,7 @@ input_file: crates/tinymist-query/src/fixtures/pkgs/touying-utils-markup-text.ty
"labelDetails": {
"description": "type"
},
"sortText": "182",
"sortText": "183",
"textEdit": {
"newText": "str(${1:})",
"range": {

View file

@ -1228,12 +1228,20 @@ impl ExprWorker<'_> {
_ => return (None, None),
};
// ref_expr.val = val.map(|v| Ty::Value(InsTy::new(v.clone())));
let val = scope
.get(name)
.cloned()
.map(|val| Ty::Value(InsTy::new(val.read().clone())));
(None, val)
if let Some(val) = val {
return (None, Some(val));
}
if name.as_ref() == "std" {
let val = Ty::Value(InsTy::new(self.ctx.world.library.std.read().clone()));
return (None, Some(val));
}
(None, None)
}
fn fold_expr_and_val(&mut self, src: ConcolicExpr) -> Option<Expr> {