fix: correct order to insert definitions in scope (#1116)

This commit is contained in:
Myriad-Dreamin 2025-01-06 15:28:22 +08:00 committed by GitHub
parent bb66b4b97a
commit b7feb5dcca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 88 additions and 7 deletions

View file

@ -54,13 +54,6 @@ impl CompletionPair<'_, '_, '_> {
};
let mode = interpret_mode_at(Some(&self.cursor.leaf));
let in_math = matches!(mode, InterpretMode::Math);
let lib = self.worker.world().library();
let scope = if in_math { &lib.math } else { &lib.global }
.scope()
.clone();
defines.insert_scope(&scope);
previous_decls(self.cursor.leaf.clone(), |node| -> Option<()> {
match node {
@ -93,6 +86,14 @@ impl CompletionPair<'_, '_, '_> {
None
});
let in_math = matches!(mode, InterpretMode::Math);
let lib = self.worker.world().library();
let scope = if in_math { &lib.math } else { &lib.global }
.scope()
.clone();
defines.insert_scope(&scope);
Some(defines)
}

View file

@ -0,0 +1,5 @@
/// contains: pagebreak
#let pagebreak(fill-rest: false) = { }
#pageb(/* range -1..0 */ )

View file

@ -0,0 +1,5 @@
/// contains: pagebreak
#let pagebreak(fill-rest: false) = { }
#page(/* range -1..0 */ )

View file

@ -0,0 +1,35 @@
---
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
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 3,
"label": "pagebreak",
"labelDetails": {
"description": "(fill-rest: false) => none"
},
"sortText": "126",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {
"end": {
"character": 6,
"line": 4
},
"start": {
"character": 1,
"line": 4
}
}
}
}
]
}
]

View file

@ -0,0 +1,35 @@
---
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
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 3,
"label": "pagebreak",
"labelDetails": {
"description": "(fill-rest: false) => none"
},
"sortText": "127",
"textEdit": {
"newText": "pagebreak()${1:}",
"range": {
"end": {
"character": 5,
"line": 4
},
"start": {
"character": 1,
"line": 4
}
}
}
}
]
}
]