From a966cc608cb0c9bdd89f75dd0ab1ba9e62c4cc4f Mon Sep 17 00:00:00 2001 From: BlockLune <39331194+BlockLune@users.noreply.github.com> Date: Wed, 20 Aug 2025 23:58:03 +0800 Subject: [PATCH] feat(wxml): add parser and queries --- SUPPORTED_LANGUAGES.md | 1 + lua/nvim-treesitter/parsers.lua | 8 ++++ runtime/queries/wxml/folds.scm | 7 +++ runtime/queries/wxml/highlights.scm | 70 +++++++++++++++++++++++++++++ runtime/queries/wxml/indents.scm | 32 +++++++++++++ runtime/queries/wxml/injections.scm | 7 +++ 6 files changed, 125 insertions(+) create mode 100644 runtime/queries/wxml/folds.scm create mode 100644 runtime/queries/wxml/highlights.scm create mode 100644 runtime/queries/wxml/indents.scm create mode 100644 runtime/queries/wxml/injections.scm diff --git a/SUPPORTED_LANGUAGES.md b/SUPPORTED_LANGUAGES.md index ceb928e72..25c5e1137 100644 --- a/SUPPORTED_LANGUAGES.md +++ b/SUPPORTED_LANGUAGES.md @@ -326,6 +326,7 @@ jsx (queries only)[^jsx] | unstable | `HFIJ ` | | @steelsojka [wgsl_bevy](https://github.com/tree-sitter-grammars/tree-sitter-wgsl-bevy) | unstable | `HFI  ` | | @theHamsta [wing](https://github.com/winglang/tree-sitter-wing) | unstable | `HF JL` | | @gshpychka, @MarkMcCulloh [wit](https://github.com/bytecodealliance/tree-sitter-wit) | unstable | `HF J ` | | @mkatychev +[wxml](https://github.com/BlockLune/tree-sitter-wxml) | unstable | `HFIJ ` | | @BlockLune [xcompose](https://github.com/tree-sitter-grammars/tree-sitter-xcompose) | unstable | `H  JL` | | @ObserverOfTime [xml](https://github.com/tree-sitter-grammars/tree-sitter-xml) | unstable | `HFIJL` | | @ObserverOfTime [xresources](https://github.com/ValdezFOmar/tree-sitter-xresources) | unstable | `HF JL` | | @ValdezFOmar diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 88732ab19..c93108679 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -2587,6 +2587,14 @@ return { maintainers = { '@mkatychev' }, tier = 2, }, + wxml = { + install_info = { + revision = '81bd97fa3bbc43516ad0e7ea5518d72651d954bf', + url = 'https://github.com/BlockLune/tree-sitter-wxml', + }, + maintainers = { '@BlockLune' }, + tier = 2, + }, xcompose = { install_info = { revision = 'a51d6366f041dbefec4da39a7eb3168a9b1cbc0e', diff --git a/runtime/queries/wxml/folds.scm b/runtime/queries/wxml/folds.scm new file mode 100644 index 000000000..df3eeeef7 --- /dev/null +++ b/runtime/queries/wxml/folds.scm @@ -0,0 +1,7 @@ +[ + (element) + (block_element) + (slot_element) + (template_element) + (wxs_element) +] @fold diff --git a/runtime/queries/wxml/highlights.scm b/runtime/queries/wxml/highlights.scm new file mode 100644 index 000000000..d71a0f4fc --- /dev/null +++ b/runtime/queries/wxml/highlights.scm @@ -0,0 +1,70 @@ +; Comments +(comment) @comment @spell + +; Text +(text) @spell + +; Tag names +(tag_name) @tag + +((tag_name) @tag.builtin + (#any-of? @tag.builtin "wxs" "template" "import" "include" "slot" "block")) + +; Attributes +(attribute_name) @tag.attribute + +(attribute_value) @string + +(quoted_attribute_value) @string + +; WeChat specific attributes +((attribute_name) @keyword.directive + (#lua-match? @keyword.directive "^wx:")) + +((attribute_name) @keyword.conditional + (#any-of? @keyword.conditional "wx:if" "wx:elif" "wx:else")) + +((attribute_name) @keyword.repeat + (#any-of? @keyword.repeat "wx:for" "wx:for-index" "wx:for-item")) + +((attribute_name) @keyword + (#match? @keyword "^(bind|catch|mut-bind):?")) + +((attribute_name) @keyword + (#match? @keyword "^(model:|data-)")) + +((attribute + (attribute_name) @_attr + (quoted_attribute_value) @string.special.url) + (#any-of? @_attr "href" "src") + (#set! @string.special.url url @string.special.url)) + +; Entity references +(entity) @string.escape + +; Raw text (primarily for wxs JavaScript content) +(raw_text) @markup.raw + +; Interpolation expressions +(interpolation) @markup.strong + +(expression) @markup.raw + +; Import and include statements +(import_statement) @keyword.import + +(include_statement) @keyword.import + +[ + "<" + ">" + "" +] @punctuation.bracket + +[ + "\"" + "'" +] @punctuation.delimiter + +"=" @operator diff --git a/runtime/queries/wxml/indents.scm b/runtime/queries/wxml/indents.scm new file mode 100644 index 000000000..30172bb37 --- /dev/null +++ b/runtime/queries/wxml/indents.scm @@ -0,0 +1,32 @@ +; inherits: html_tags + +(block_element) @indent.begin + +(template_element) @indent.begin + +(wxs_element) @indent.begin + +(block_element + (block_end_tag + ">" @indent.end)) + +(template_element + (template_end_tag + ">" @indent.end)) + +(wxs_element + (wxs_end_tag + ">" @indent.end)) + +(block_element + (block_end_tag) @indent.branch) + +(template_element + (template_end_tag) @indent.branch) + +(wxs_element + (wxs_end_tag) @indent.branch) + +(import_statement) @indent.ignore + +(include_statement) @indent.ignore diff --git a/runtime/queries/wxml/injections.scm b/runtime/queries/wxml/injections.scm new file mode 100644 index 000000000..0bc3440af --- /dev/null +++ b/runtime/queries/wxml/injections.scm @@ -0,0 +1,7 @@ +((raw_text) @injection.content + (#set! injection.language "javascript") + (#set! injection.include-children)) + +((expression) @injection.content + (#set! injection.language "javascript") + (#set! injection.include-children))