fix: complete where and with after dots (#1871)

This commit is contained in:
Myriad-Dreamin 2025-07-05 20:53:39 +08:00 committed by GitHub
parent 1478280a07
commit c767c37cc1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 180 additions and 22 deletions

View file

@ -46,12 +46,17 @@ impl CompletionPair<'_, '_, '_> {
});
}
let bad_instantiate = matches!(
self.cursor.surrounding_syntax,
SurroundingSyntax::Selector | SurroundingSyntax::SetRule
) && !fn_feat.is_element;
let bad_instantiate = match self.cursor.surrounding_syntax {
// todo: filter invalid function as a selector.
SurroundingSyntax::Selector => name == "with",
SurroundingSyntax::SetRule => !fn_feat.is_element,
_ => false,
};
if !bad_instantiate {
if !parens || matches!(self.cursor.surrounding_syntax, SurroundingSyntax::Selector) {
if !parens
|| (matches!(self.cursor.surrounding_syntax, SurroundingSyntax::Selector)
&& fn_feat.is_element)
{
self.push_completion(Completion {
label: name,
..base

View file

@ -1,2 +1,2 @@
/// contains: raw, read, raw.with, raw.where, read.with, read.where, replacement, regex selector, red
/// contains: raw, read, raw.with, raw.where, raw.line, read.with, read.where, replacement, regex selector, red
#show r/* range 0..1 */

View file

@ -1,2 +1,2 @@
/// contains: raw, read, raw.with, raw.where, read.with, read.where, replacement, regex selector, red
/// contains: raw, read, raw.with, raw.where, raw.line, read.with, read.where, replacement, regex selector, red
#show /* range 0..1 */

View file

@ -1,2 +1,2 @@
/// contains: raw, read, raw.with, raw.where, read.with, read.where, replacement, regex selector
/// contains: raw, read, raw.with, raw.where, raw.line, read.with, read.where, replacement, regex selector
#show /* range 0..1 */:

View file

@ -0,0 +1,2 @@
/// contains: raw, with, where, line, line.with, line.where
#show raw./* range 0..1 */

View file

@ -1,6 +1,6 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on / (109..110)
description: Completion on / (119..120)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/show.typ
---
@ -18,7 +18,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "133",
"sortText": "165",
"textEdit": {
"newText": "raw: ${1:}",
"range": {
@ -43,7 +43,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "134",
"sortText": "166",
"textEdit": {
"newText": "raw.where(${1:}): ${2:}",
"range": {
@ -58,13 +58,38 @@ input_file: crates/tinymist-query/src/fixtures/completion/show.typ
}
}
},
{
"command": {
"command": "tinymist.triggerSuggestAndParameterHints",
"title": ""
},
"kind": 3,
"label": "read",
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "167",
"textEdit": {
"newText": "read(${1:}): ${2:}",
"range": {
"end": {
"character": 7,
"line": 1
},
"start": {
"character": 6,
"line": 1
}
}
}
},
{
"kind": 6,
"label": "red",
"labelDetails": {
"description": "rgb(\"#ff4136\")"
},
"sortText": "137",
"sortText": "170",
"textEdit": {
"newText": "red: ${1:}",
"range": {
@ -86,7 +111,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show.typ
},
"kind": 15,
"label": "regex selector",
"sortText": "140",
"sortText": "174",
"textEdit": {
"newText": "regex(\"${1:regex}\"): ${2:}",
"range": {

View file

@ -1,6 +1,6 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on / (108..109)
description: Completion on / (118..119)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/show2.typ
---
@ -18,7 +18,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show2.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "133",
"sortText": "165",
"textEdit": {
"newText": "raw: ${1:}",
"range": {
@ -43,7 +43,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show2.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "134",
"sortText": "166",
"textEdit": {
"newText": "raw.where(${1:}): ${2:}",
"range": {
@ -58,13 +58,38 @@ input_file: crates/tinymist-query/src/fixtures/completion/show2.typ
}
}
},
{
"command": {
"command": "tinymist.triggerSuggestAndParameterHints",
"title": ""
},
"kind": 3,
"label": "read",
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "167",
"textEdit": {
"newText": "read(${1:}): ${2:}",
"range": {
"end": {
"character": 6,
"line": 1
},
"start": {
"character": 6,
"line": 1
}
}
}
},
{
"kind": 6,
"label": "red",
"labelDetails": {
"description": "rgb(\"#ff4136\")"
},
"sortText": "137",
"sortText": "170",
"textEdit": {
"newText": "red: ${1:}",
"range": {
@ -86,7 +111,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show2.typ
},
"kind": 15,
"label": "regex selector",
"sortText": "140",
"sortText": "174",
"textEdit": {
"newText": "regex(\"${1:regex}\"): ${2:}",
"range": {

View file

@ -1,6 +1,6 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on / (103..104)
description: Completion on / (113..114)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/show3.typ
---
@ -18,7 +18,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show3.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "133",
"sortText": "165",
"textEdit": {
"newText": "raw: ${1:}",
"range": {
@ -43,7 +43,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show3.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "134",
"sortText": "166",
"textEdit": {
"newText": "raw.where(${1:}): ${2:}",
"range": {
@ -58,6 +58,31 @@ input_file: crates/tinymist-query/src/fixtures/completion/show3.typ
}
}
},
{
"command": {
"command": "tinymist.triggerSuggestAndParameterHints",
"title": ""
},
"kind": 3,
"label": "read",
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "167",
"textEdit": {
"newText": "read(${1:}): ${2:}",
"range": {
"end": {
"character": 6,
"line": 1
},
"start": {
"character": 6,
"line": 1
}
}
}
},
{
"command": {
"command": "editor.action.triggerSuggest",
@ -65,7 +90,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show3.typ
},
"kind": 15,
"label": "regex selector",
"sortText": "140",
"sortText": "174",
"textEdit": {
"newText": "regex(\"${1:regex}\"): ${2:}",
"range": {

View file

@ -0,0 +1,76 @@
---
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/show_dot.typ
---
[
{
"isIncomplete": false,
"items": [
{
"command": {
"command": "tinymist.triggerSuggestAndParameterHints",
"title": ""
},
"kind": 3,
"label": "line",
"textEdit": {
"newText": "line",
"range": {
"end": {
"character": 10,
"line": 1
},
"start": {
"character": 10,
"line": 1
}
}
}
},
{
"command": {
"command": "tinymist.triggerSuggestAndParameterHints",
"title": ""
},
"kind": 3,
"label": "line.where",
"textEdit": {
"newText": "line.where(${1:})",
"range": {
"end": {
"character": 10,
"line": 1
},
"start": {
"character": 10,
"line": 1
}
}
}
},
{
"command": {
"command": "tinymist.triggerSuggestAndParameterHints",
"title": ""
},
"kind": 3,
"label": "where",
"textEdit": {
"newText": "where(${1:})",
"range": {
"end": {
"character": 10,
"line": 1
},
"start": {
"character": 10,
"line": 1
}
}
}
}
]
}
]