diff --git a/crates/tinymist-query/src/analysis/completion/scope.rs b/crates/tinymist-query/src/analysis/completion/scope.rs index bd3797aa..a6361751 100644 --- a/crates/tinymist-query/src/analysis/completion/scope.rs +++ b/crates/tinymist-query/src/analysis/completion/scope.rs @@ -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) } diff --git a/crates/tinymist-query/src/fixtures/completion/module_show.typ b/crates/tinymist-query/src/fixtures/completion/module_show.typ new file mode 100644 index 00000000..e35f38ed --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/module_show.typ @@ -0,0 +1,2 @@ +/// contains: std +#show raw: s/* range 0..1 */ diff --git a/crates/tinymist-query/src/fixtures/completion/module_std.typ b/crates/tinymist-query/src/fixtures/completion/module_std.typ new file mode 100644 index 00000000..cc6eeae8 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/module_std.typ @@ -0,0 +1,2 @@ +/// contains: std +#s/* range 0..1 */ diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@bracket_strong.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@bracket_strong.typ.snap index f50a4da0..e68aabd7 100644 --- a/crates/tinymist-query/src/fixtures/completion/snaps/test@bracket_strong.typ.snap +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@bracket_strong.typ.snap @@ -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": { diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@module_show.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@module_show.typ.snap new file mode 100644 index 00000000..c035c19e --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@module_show.typ.snap @@ -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": [] + } +] diff --git a/crates/tinymist-query/src/fixtures/completion/snaps/test@module_std.typ.snap b/crates/tinymist-query/src/fixtures/completion/snaps/test@module_std.typ.snap new file mode 100644 index 00000000..86ad6ca5 --- /dev/null +++ b/crates/tinymist-query/src/fixtures/completion/snaps/test@module_std.typ.snap @@ -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 + } + } + } + } + ] + } +] diff --git a/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-cover-with-rect.typ.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-cover-with-rect.typ.snap index 66baa557..6bc6b439 100644 --- a/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-cover-with-rect.typ.snap +++ b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-cover-with-rect.typ.snap @@ -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": { diff --git a/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-markup-text.typ.snap b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-markup-text.typ.snap index 2628c975..3e4ce8c8 100644 --- a/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-markup-text.typ.snap +++ b/crates/tinymist-query/src/fixtures/pkgs/snaps/test@touying-utils-markup-text.typ.snap @@ -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": { diff --git a/crates/tinymist-query/src/syntax/expr.rs b/crates/tinymist-query/src/syntax/expr.rs index a5201897..0cf5b22b 100644 --- a/crates/tinymist-query/src/syntax/expr.rs +++ b/crates/tinymist-query/src/syntax/expr.rs @@ -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 { diff --git a/tests/e2e/main.rs b/tests/e2e/main.rs index f158b55d..11bd4396 100644 --- a/tests/e2e/main.rs +++ b/tests/e2e/main.rs @@ -374,7 +374,7 @@ fn e2e() { }); let hash = replay_log(&tinymist_binary, &root.join("neovim")); - insta::assert_snapshot!(hash, @"siphash128_13:2655017d733b6c6c753d92c5d5bbc65d"); + insta::assert_snapshot!(hash, @"siphash128_13:ce179598883927533514674aa7930054"); } { @@ -385,7 +385,7 @@ fn e2e() { }); let hash = replay_log(&tinymist_binary, &root.join("vscode")); - insta::assert_snapshot!(hash, @"siphash128_13:934ee53fdb376bbeba357953499f7a5f"); + insta::assert_snapshot!(hash, @"siphash128_13:60813619e4478214e898a3d277ac031b"); } }