diff --git a/lockfile.json b/lockfile.json index 82429e8eb..9a89d29e6 100644 --- a/lockfile.json +++ b/lockfile.json @@ -715,5 +715,8 @@ }, "zig": { "revision": "0d08703e4c3f426ec61695d7617415fff97029bd" + }, + "templ": { + "revision": "94ea27668915ef8f084c9fd7174cfd384ac9a275" } } diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 9bd3521ef..9077bc8d4 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -2095,6 +2095,14 @@ list.zig = { maintainers = { "@maxxnino" }, } +list.templ = { + install_info = { + url = "https://github.com/vrischmann/tree-sitter-templ", + files = { "src/parser.c", "src/scanner.c" }, + }, + maintainers = { "@vrischmann" }, +} + local M = { list = list, filetype_to_parsername = filetype_to_parsername, diff --git a/queries/templ/highlights.scm b/queries/templ/highlights.scm new file mode 100644 index 000000000..a7a0718e6 --- /dev/null +++ b/queries/templ/highlights.scm @@ -0,0 +1,47 @@ +; inherits: go + +(component_declaration + name: (component_identifier) @function) + +[ + (tag_start) + (tag_end) + (self_closing_tag) + (style_element) +] @tag + +(attribute + name: (attribute_name) @tag.attribute) +(attribute + value: (quoted_attribute_value) @string) + +[ + (element_text) + (style_element_text) +] @string.special + +(css_identifier) @function +(css_property + name: (css_property_name) @attribute) +(css_property + value: (css_property_value) @attribute) + +[ + (expression) + (dynamic_class_attribute_value) +] @method + +(component_import + name: (component_identifier) @function) + +(component_render) @function.call + +(element_comment) @comment @spell + +"@" @operator + +[ + "templ" + "css" + "script" +] @keyword diff --git a/queries/templ/injections.scm b/queries/templ/injections.scm new file mode 100644 index 000000000..54e8d6f68 --- /dev/null +++ b/queries/templ/injections.scm @@ -0,0 +1,8 @@ +; inherits: go + +((element_comment) @injection.content (#set! injection.language "comment")) + +((script_block_text) @injection.content (#set! injection.language "javascript")) +((script_element_text) @injection.content (#set! injection.language "javascript")) + +((style_element_text) @injection.content (#set! injection.language "css"))