mirror of
https://github.com/Myriad-Dreamin/tinymist.git
synced 2025-08-03 17:58:17 +00:00
feat: accept arbitrary expressions in show rules (#1484)
* feat: accept arbitray expressions in show rules * test: update snapshot
This commit is contained in:
parent
e8507fea96
commit
512f93176f
12 changed files with 171 additions and 34 deletions
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
/// contains: calc
|
||||
#ca/* range 0..1 */
|
|
@ -0,0 +1,2 @@
|
|||
/// contains: calc
|
||||
#show raw: ca/* range 0..1 */
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue