feat: accept arbitrary expressions in show rules (#1484)

* feat: accept arbitray expressions in show rules

* test: update snapshot
This commit is contained in:
Myriad-Dreamin 2025-03-10 23:20:13 +08:00 committed by GitHub
parent e8507fea96
commit 512f93176f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 171 additions and 34 deletions

View file

@ -124,16 +124,17 @@ impl CompletionPair<'_, '_, '_> {
SurroundingSyntax::Regular => true,
SurroundingSyntax::StringContent => false,
SurroundingSyntax::ImportList | SurroundingSyntax::ParamList => false,
SurroundingSyntax::Selector => 'selector: {
for func in &checker.functions {
if func.element().is_some() {
break 'selector true;
}
}
// SurroundingSyntax::Selector => 'selector: {
// for func in &checker.functions {
// if func.element().is_some() {
// break 'selector true;
// }
// }
false
}
SurroundingSyntax::ShowTransform => !checker.functions.is_empty(),
// false
// }
// SurroundingSyntax::ShowTransform => !checker.functions.is_empty(),
SurroundingSyntax::Selector | SurroundingSyntax::ShowTransform => true,
SurroundingSyntax::SetRule => 'set_rule: {
// todo: user defined elements
for func in &checker.functions {

View file

@ -0,0 +1,2 @@
/// contains: calc
#ca/* range 0..1 */

View file

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

View file

@ -0,0 +1,34 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on / (22..23)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/module_calc.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 9,
"label": "calc",
"labelDetails": {
"description": "module(\"calc\")"
},
"sortText": "020",
"textEdit": {
"newText": "calc",
"range": {
"end": {
"character": 3,
"line": 1
},
"start": {
"character": 1,
"line": 1
}
}
}
}
]
}
]

View file

@ -7,6 +7,28 @@ input_file: crates/tinymist-query/src/fixtures/completion/module_show.typ
[
{
"isIncomplete": false,
"items": []
"items": [
{
"kind": 9,
"label": "std",
"labelDetails": {
"description": "module(\"global\")"
},
"sortText": "263",
"textEdit": {
"newText": "std",
"range": {
"end": {
"character": 12,
"line": 1
},
"start": {
"character": 11,
"line": 1
}
}
}
}
]
}
]

View file

@ -0,0 +1,34 @@
---
source: crates/tinymist-query/src/completion.rs
description: Completion on / (32..33)
expression: "JsonRepr::new_pure(results)"
input_file: crates/tinymist-query/src/fixtures/completion/module_show_calc.typ
---
[
{
"isIncomplete": false,
"items": [
{
"kind": 9,
"label": "calc",
"labelDetails": {
"description": "module(\"calc\")"
},
"sortText": "027",
"textEdit": {
"newText": "calc",
"range": {
"end": {
"character": 13,
"line": 1
},
"start": {
"character": 11,
"line": 1
}
}
}
}
]
}
]

View file

@ -14,7 +14,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": "096",
"sortText": "133",
"textEdit": {
"newText": "raw: ${1:}",
"range": {
@ -35,7 +35,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": "097",
"sortText": "134",
"textEdit": {
"newText": "raw.where(${1:}): ${2:}",
"range": {
@ -50,10 +50,31 @@ input_file: crates/tinymist-query/src/fixtures/completion/show.typ
}
}
},
{
"kind": 6,
"label": "red",
"labelDetails": {
"description": "rgb(\"#ff4136\")"
},
"sortText": "137",
"textEdit": {
"newText": "red: ${1:}",
"range": {
"end": {
"character": 7,
"line": 1
},
"start": {
"character": 6,
"line": 1
}
}
}
},
{
"kind": 15,
"label": "regex selector",
"sortText": "102",
"sortText": "140",
"textEdit": {
"newText": "regex(\"${1:regex}\"): ${2:}",
"range": {

View file

@ -14,7 +14,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": "096",
"sortText": "133",
"textEdit": {
"newText": "raw: ${1:}",
"range": {
@ -35,7 +35,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": "097",
"sortText": "134",
"textEdit": {
"newText": "raw.where(${1:}): ${2:}",
"range": {
@ -50,10 +50,31 @@ input_file: crates/tinymist-query/src/fixtures/completion/show2.typ
}
}
},
{
"kind": 6,
"label": "red",
"labelDetails": {
"description": "rgb(\"#ff4136\")"
},
"sortText": "137",
"textEdit": {
"newText": "red: ${1:}",
"range": {
"end": {
"character": 6,
"line": 1
},
"start": {
"character": 6,
"line": 1
}
}
}
},
{
"kind": 15,
"label": "regex selector",
"sortText": "102",
"sortText": "140",
"textEdit": {
"newText": "regex(\"${1:regex}\"): ${2:}",
"range": {

View file

@ -14,7 +14,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": "096",
"sortText": "133",
"textEdit": {
"newText": "raw: ${1:}",
"range": {
@ -35,7 +35,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": "097",
"sortText": "134",
"textEdit": {
"newText": "raw.where(${1:}): ${2:}",
"range": {
@ -53,7 +53,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show3.typ
{
"kind": 15,
"label": "regex selector",
"sortText": "102",
"sortText": "140",
"textEdit": {
"newText": "regex(\"${1:regex}\"): ${2:}",
"range": {

View file

@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "175",
"sortText": "212",
"textEdit": {
"newText": "raw(${1:})",
"range": {
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "176",
"sortText": "213",
"textEdit": {
"newText": "raw.with(${1:})",
"range": {
@ -56,7 +56,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "177",
"sortText": "214",
"textEdit": {
"newText": "read(${1:})",
"range": {
@ -77,7 +77,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "178",
"sortText": "215",
"textEdit": {
"newText": "read.with(${1:})",
"range": {
@ -95,7 +95,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform.typ
{
"kind": 15,
"label": "replacement",
"sortText": "189",
"sortText": "228",
"textEdit": {
"newText": "[${1:content}]",
"range": {

View file

@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "175",
"sortText": "212",
"textEdit": {
"newText": "raw(${1:})",
"range": {
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "176",
"sortText": "213",
"textEdit": {
"newText": "raw.with(${1:})",
"range": {
@ -56,7 +56,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "177",
"sortText": "214",
"textEdit": {
"newText": "read(${1:})",
"range": {
@ -77,7 +77,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "178",
"sortText": "215",
"textEdit": {
"newText": "read.with(${1:})",
"range": {
@ -95,7 +95,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform2.typ
{
"kind": 15,
"label": "replacement",
"sortText": "189",
"sortText": "228",
"textEdit": {
"newText": "[${1:content}]",
"range": {

View file

@ -14,7 +14,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "175",
"sortText": "212",
"textEdit": {
"newText": " raw(${1:})",
"range": {
@ -35,7 +35,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
"labelDetails": {
"description": "(str, align: alignment, block: bool, lang: none | str, syntaxes: [syntax], tab-size: int, theme: [theme]) => raw"
},
"sortText": "176",
"sortText": "213",
"textEdit": {
"newText": " raw.with(${1:})",
"range": {
@ -56,7 +56,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "177",
"sortText": "214",
"textEdit": {
"newText": " read(${1:})",
"range": {
@ -77,7 +77,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
"labelDetails": {
"description": "([any], encoding: \"utf8\" | none) => bytes | str"
},
"sortText": "178",
"sortText": "215",
"textEdit": {
"newText": " read.with(${1:})",
"range": {
@ -95,7 +95,7 @@ input_file: crates/tinymist-query/src/fixtures/completion/show_transform3.typ
{
"kind": 15,
"label": "replacement",
"sortText": "189",
"sortText": "228",
"textEdit": {
"newText": " [${1:content}]",
"range": {