From 90d6de64387a668c23f4359c7c273ac13a3ecc7f Mon Sep 17 00:00:00 2001 From: BlockLune <39331194+BlockLune@users.noreply.github.com> Date: Tue, 19 Aug 2025 20:03:13 +0800 Subject: [PATCH] feat(wxml): add parser and queries --- lockfile.json | 3 + lua/nvim-treesitter/parsers.lua | 8 +++ queries/wxml/folds.scm | 7 ++ queries/wxml/highlights.scm | 109 ++++++++++++++++++++++++++++++++ queries/wxml/indents.scm | 25 ++++++++ queries/wxml/injections.scm | 7 ++ 6 files changed, 159 insertions(+) create mode 100644 queries/wxml/folds.scm create mode 100644 queries/wxml/highlights.scm create mode 100644 queries/wxml/indents.scm create mode 100644 queries/wxml/injections.scm diff --git a/lockfile.json b/lockfile.json index 3f87966c6..79385f1a9 100644 --- a/lockfile.json +++ b/lockfile.json @@ -926,6 +926,9 @@ "wit": { "revision": "81490b4e74c792369e005f72b0d46fe082d3fed2" }, + "wxml": { + "revision": "4487d2eab73191b93279c98ed31c8e8038c5441f" + }, "xcompose": { "revision": "fff3e72242aa110ebba6441946ea4d12d200fa68" }, diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 31b691209..a08e12e60 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -2667,6 +2667,14 @@ list.wit = { maintainers = { "@liamwh" }, } +list.wxml = { + install_info = { + url = "https://github.com/BlockLune/tree-sitter-wxml", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@BlockLune" }, +} + list.xcompose = { install_info = { url = "https://github.com/ObserverOfTime/tree-sitter-xcompose", diff --git a/queries/wxml/folds.scm b/queries/wxml/folds.scm new file mode 100644 index 000000000..ee0e6e745 --- /dev/null +++ b/queries/wxml/folds.scm @@ -0,0 +1,7 @@ +[ + (element) + (template_element) + (slot_element) + (block_element) + (wxs_element) +] @fold diff --git a/queries/wxml/highlights.scm b/queries/wxml/highlights.scm new file mode 100644 index 000000000..c3d07416d --- /dev/null +++ b/queries/wxml/highlights.scm @@ -0,0 +1,109 @@ +; Comments +(comment) @comment + +; Document structure +(document) @none + +; Elements and tags +(element) @none + +(start_tag) @none + +(end_tag) @none + +(self_closing_tag) @none + +; Tag names +(tag_name) @tag + +; WeChat Mini Program specific tags +((tag_name) @keyword + (#any-of? @keyword "wxs" "template" "import" "include" "slot" "block")) + +; Attributes +(attribute) @none + +(attribute_name) @property + +(attribute_value) @string + +(quoted_attribute_value) @string + +; Entity references +(entity) @string.escape + +; Text content +(text) @text.literal + +; Raw text (primarily for wxs JavaScript content) +(raw_text) @embedded + +; Interpolation expressions +(interpolation) @punctuation.special + +(expression) @embedded + +; Import and include statements +(import_statement) @preproc + +(include_statement) @preproc + +; Template elements +(template_element) @none + +(template_start_tag) @none + +(template_end_tag) @none + +; Slot elements +(slot_element) @none + +(slot_start_tag) @none + +(slot_end_tag) @none + +; Block elements +(block_element) @none + +(block_start_tag) @none + +(block_end_tag) @none + +; WXS elements (JavaScript modules) +(wxs_element) @none + +(wxs_start_tag) @none + +(wxs_end_tag) @none + +; WeChat specific directive attributes +((attribute_name) @emphasis.strong + (#match? @emphasis.strong "^wx:")) + +; Event binding attributes +((attribute_name) @emphasis.strong + (#match? @emphasis.strong "^(bind|catch|mut-bind):?")) + +; Data binding attributes +((attribute_name) @emphasis.strong + (#match? @emphasis.strong "^(model:|data-)")) + +; Special attributes +((attribute_name) @property.special + (#any-of? @property.special "slot" "is" "module" "src")) + +; Punctuation and operators +"<" @punctuation.bracket + +">" @punctuation.bracket + +"" @punctuation.bracket + +"=" @operator + +; Quotes in attributes +"\"" @punctuation.delimiter + +"'" @punctuation.delimiter diff --git a/queries/wxml/indents.scm b/queries/wxml/indents.scm new file mode 100644 index 000000000..4e8c76344 --- /dev/null +++ b/queries/wxml/indents.scm @@ -0,0 +1,25 @@ +(start_tag + ">" @end) @indent + +(self_closing_tag + "/>" @end) @indent + +(element + (start_tag) @start + (end_tag)? @end) @indent + +(block_element + (block_start_tag) @start + (block_end_tag)? @end) @indent + +(slot_element + (slot_start_tag) @start + (slot_end_tag)? @end) @indent + +(template_element + (template_start_tag) @start + (template_end_tag)? @end) @indent + +(wxs_element + (wxs_start_tag) @start + (wxs_end_tag)? @end) @indent diff --git a/queries/wxml/injections.scm b/queries/wxml/injections.scm new file mode 100644 index 000000000..0bc3440af --- /dev/null +++ b/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))