From 26ec1cf39a3c5f548f199918b0a84d614a5c6be7 Mon Sep 17 00:00:00 2001 From: alois31 <36605164+alois31@users.noreply.github.com> Date: Wed, 23 Nov 2022 04:49:02 +0100 Subject: [PATCH] Add QML language support (#4842) Fixes https://github.com/helix-editor/helix/issues/2771 --- book/src/generated/lang-support.md | 1 + languages.toml | 13 +++++ runtime/queries/qml/highlights.scm | 90 ++++++++++++++++++++++++++++++ runtime/queries/qml/indents.scm | 6 ++ runtime/queries/qml/injections.scm | 16 ++++++ 5 files changed, 126 insertions(+) create mode 100644 runtime/queries/qml/highlights.scm create mode 100644 runtime/queries/qml/indents.scm create mode 100644 runtime/queries/qml/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 59b60851a..ac9550369 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -93,6 +93,7 @@ | protobuf | ✓ | | ✓ | | | purescript | ✓ | | | `purescript-language-server` | | python | ✓ | ✓ | ✓ | `pylsp` | +| qml | ✓ | | ✓ | `qmlls` | | r | ✓ | | | `R` | | racket | | | | `racket` | | regex | ✓ | | | | diff --git a/languages.toml b/languages.toml index 47d77feed..1e7dcbf79 100644 --- a/languages.toml +++ b/languages.toml @@ -1980,3 +1980,16 @@ language-server = { command = "bicep-langserver" } [[grammar]] name = "bicep" source = { git = "https://github.com/the-mikedavis/tree-sitter-bicep", rev = "d8e097fcfa143854861ef737161163a09cc2916b" } + +[[language]] +name = "qml" +scope = "source.qml" +file-types = ["qml"] +roots = [] +language-server = { command = "qmlls" } +indent = { tab-width = 4, unit = " " } +grammar = "qmljs" + +[[grammar]] +name = "qmljs" +source = { git = "https://github.com/yuja/tree-sitter-qmljs", rev = "0b2b25bcaa7d4925d5f0dda16f6a99c588a437f1" } diff --git a/runtime/queries/qml/highlights.scm b/runtime/queries/qml/highlights.scm new file mode 100644 index 000000000..11178fcdb --- /dev/null +++ b/runtime/queries/qml/highlights.scm @@ -0,0 +1,90 @@ +(comment) @comment + +(ui_import + source: _ @namespace + version: _? @constant + alias: _? @namespace) + +(ui_pragma + name: (identifier) @attribute + value: (identifier)? @constant) + +(ui_annotation + "@" @punctuation + type_name: _ @type) + +;;; Declarations + +(enum_declaration + name: (identifier) @type) + +(enum_assignment + name: (identifier) @constant + value: _ @constant) + +(enum_body + name: (identifier) @constant) + +(ui_inline_component + name: (identifier) @type) + +(ui_object_definition + type_name: _ @type) + +(ui_object_definition_binding + type_name: _ @type + name: _ @variable.other.member) + +(ui_property + type: _ @type + name: (identifier) @variable.other.member) + +(ui_signal + name: (identifier) @function) + +(ui_signal_parameter + name: (identifier) @variable.parameter + type: _ @type) + +(ui_signal_parameter + type: _ @type + name: (identifier) @variable.parameter);;; Properties and bindings + +;;; Bindings + +(ui_binding + name: _ @variable.other.member) + +;;; Other + +[ + "(" + ")" + "{" + "}" +] @punctuation.bracket + +(ui_list_property_type [ + "<" + ">" +] @punctuation.bracket) + +[ + "," + "." + ":" +] @punctuation.delimiter + +[ + "as" + "component" + "default" + "enum" + "import" + "on" + "pragma" + "property" + "readonly" + "required" + "signal" +] @keyword diff --git a/runtime/queries/qml/indents.scm b/runtime/queries/qml/indents.scm new file mode 100644 index 000000000..074922837 --- /dev/null +++ b/runtime/queries/qml/indents.scm @@ -0,0 +1,6 @@ +[ + (enum_body) + (ui_object_initializer) +] @indent + +"}" @outdent diff --git a/runtime/queries/qml/injections.scm b/runtime/queries/qml/injections.scm new file mode 100644 index 000000000..1ce987d35 --- /dev/null +++ b/runtime/queries/qml/injections.scm @@ -0,0 +1,16 @@ +((comment) @injection.content + (#set! injection.language "comment")) + +([ + (empty_statement) + (expression_statement) + (function_declaration) + (generator_function_declaration) + (statement_block) + (switch_statement) + (try_statement) + (variable_declaration) + (with_statement) + ] @injection.content + (#set! injection.include-children) + (#set! injection.language "javascript"))