From 6c6607ef62a87a81f0b031fcd2376cec5c4c93bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristoffer=20Plagborg=20Bak=20S=C3=B8rensen?= <57013304+kpbaks@users.noreply.github.com> Date: Fri, 4 Jul 2025 04:19:22 +0200 Subject: [PATCH] queries: add textobjects for qml (#13855) --- book/src/generated/lang-support.md | 2 +- runtime/queries/qml/textobjects.scm | 49 +++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 runtime/queries/qml/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index f16644a19..4f1191b33 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -189,7 +189,7 @@ | pug | ✓ | | | | | purescript | ✓ | ✓ | | `purescript-language-server` | | python | ✓ | ✓ | ✓ | `ty`, `ruff`, `jedi-language-server`, `pylsp` | -| qml | ✓ | | ✓ | `qmlls` | +| qml | ✓ | ✓ | ✓ | `qmlls` | | quarto | ✓ | | ✓ | | | quint | ✓ | | | `quint-language-server` | | r | ✓ | | | `R` | diff --git a/runtime/queries/qml/textobjects.scm b/runtime/queries/qml/textobjects.scm new file mode 100644 index 000000000..136627429 --- /dev/null +++ b/runtime/queries/qml/textobjects.scm @@ -0,0 +1,49 @@ +; (comment) is used for both // and /* ... */ comment syntax +(comment) @comment.inside +(comment)+ @comment.around + +(ui_object_definition + initializer: (_) @class.inside) @class.around + +(ui_binding + name: (identifier) @parameter.inside) @parameter.around + +(ui_property + (_)+ @parameter.inside ":") @parameter.around + +(function_declaration + body: (_) @function.inside) @function.around + +(arrow_function + body: (_) @function.inside) @function.around + +; e.g. `onClicked: console.log("Button clicked!")` +((ui_binding + name: (identifier) @_name + value: (_) @function.around @function.inside) + (#match? @_name "^on[A-Z].*")) + +; e.g. +; Component.onCompleted: { +; console.log("completed") +; } +(statement_block (expression_statement)* @function.inside) @function.around + +; e.g. +; states: [ +; State { name: "activated" }, +; State { name: "deactivated" } +; ] +(ui_object_array + ((_) @entry.inside . ","? @entry.around) @entry.around) + +; e.g. [1, 2, 3, 4] +(array + ((_) @entry.inside . ","? @entry.around) @entry.around) + +; Tests in QML are written using "Qt Quick Test" and it's `TestCase` type +; ref: https://doc.qt.io/qt-6/qtquicktest-index.html +((ui_object_definition + type_name: (identifier) @_name + initializer: (_) @test.inside) @test.around + (#eq? @_name "TestCase"))