From ac91b309c1e26134ae36ce7ef92edf4ffc6ebe85 Mon Sep 17 00:00:00 2001 From: David Else <12832280+David-Else@users.noreply.github.com> Date: Wed, 12 Nov 2025 02:14:36 +0000 Subject: [PATCH] Update tree-sitter-go-template + highlights and Inject HTML (#14746) --- languages.toml | 2 +- runtime/queries/gotmpl/highlights.scm | 51 +++++++++++++++++++++------ runtime/queries/gotmpl/injections.scm | 3 ++ runtime/queries/gotmpl/locals.scm | 12 +++++++ 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 runtime/queries/gotmpl/locals.scm diff --git a/languages.toml b/languages.toml index 09b05968..58b1e813 100644 --- a/languages.toml +++ b/languages.toml @@ -858,7 +858,7 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "gotmpl" -source = { git = "https://github.com/dannylongeuay/tree-sitter-go-template", rev = "395a33e08e69f4155156f0b90138a6c86764c979" } +source = { git = "https://github.com/ngalaiko/tree-sitter-go-template", rev = "ca26229bafcd3f37698a2496c2a5efa2f07e86bc" } [[language]] name = "gowork" diff --git a/runtime/queries/gotmpl/highlights.scm b/runtime/queries/gotmpl/highlights.scm index 2f47f4bd..11928b43 100644 --- a/runtime/queries/gotmpl/highlights.scm +++ b/runtime/queries/gotmpl/highlights.scm @@ -19,6 +19,7 @@ ; Operators "|" @operator +"=" @operator ":=" @operator ; Builtin functions @@ -38,16 +39,43 @@ ")" @punctuation.bracket "(" @punctuation.bracket -; Keywords - -"else" @keyword -"if" @keyword -"range" @keyword -"with" @keyword -"end" @keyword -"template" @keyword -"define" @keyword -"block" @keyword +; Actions + +(if_action + [ + "if" + "else" + "end" + ] @keyword.control.conditional) + +(range_action + [ + "range" + "else" + "end" + ] @keyword.control.conditional) + +(template_action + "template" @function.builtin) + +(block_action + [ + "block" + "end" + ] @keyword.directive) + +(define_action + [ + "define" + "end" + ] @keyword.directive) + +(with_action + [ + "with" + "else" + "end" + ] @keyword.control.conditional) ; Literals @@ -61,10 +89,11 @@ [ (int_literal) - (float_literal) (imaginary_literal) ] @constant.numeric.integer +(float_literal) @constant.numeric.float + [ (true) (false) diff --git a/runtime/queries/gotmpl/injections.scm b/runtime/queries/gotmpl/injections.scm index 321c90ad..3b3d074c 100644 --- a/runtime/queries/gotmpl/injections.scm +++ b/runtime/queries/gotmpl/injections.scm @@ -1,2 +1,5 @@ ((comment) @injection.content (#set! injection.language "comment")) +((text) @injection.content + (#set! injection.language "html") + (#set! injection.combined)) diff --git a/runtime/queries/gotmpl/locals.scm b/runtime/queries/gotmpl/locals.scm new file mode 100644 index 00000000..0112db5e --- /dev/null +++ b/runtime/queries/gotmpl/locals.scm @@ -0,0 +1,12 @@ +[ + (if_action) + (range_action) + (block_action) + (with_action) + (define_action) +] @local.scope + +(variable_definition + variable: (variable) @local.definition.variable) + +(variable) @local.reference -- 2.51.2