From 483b970d3203de4152a70e637cb2413d697d5394 Mon Sep 17 00:00:00 2001 From: dannylongeuay Date: Sun, 17 Jul 2022 15:56:16 -0700 Subject: [PATCH 1/3] feat(tree-sitter): :sparkles: add go template support --- book/src/generated/lang-support.md | 1 + languages.toml | 14 +++++ runtime/queries/gotmpl/highlights.scm | 75 +++++++++++++++++++++++++++ runtime/queries/gotmpl/injections.scm | 2 + 4 files changed, 92 insertions(+) create mode 100644 runtime/queries/gotmpl/highlights.scm create mode 100644 runtime/queries/gotmpl/injections.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index aecf80acb305..b29eb52a88c8 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -34,6 +34,7 @@ | glsl | ✓ | ✓ | ✓ | | | go | ✓ | ✓ | ✓ | `gopls` | | gomod | ✓ | | | `gopls` | +| gotmpl | ✓ | | | `gopls` | | gowork | ✓ | | | `gopls` | | graphql | ✓ | | | | | hare | ✓ | | ✓ | | diff --git a/languages.toml b/languages.toml index f9dac467ea2c..1e0f8954a2cd 100644 --- a/languages.toml +++ b/languages.toml @@ -285,6 +285,20 @@ indent = { tab-width = 4, unit = "\t" } name = "gomod" source = { git = "https://github.com/camdencheek/tree-sitter-go-mod", rev = "e8f51f8e4363a3d9a427e8f63f4c1bbc5ef5d8d0" } +[[language]] +name = "gotmpl" +scope = "source.gotmpl" +injection-regex = "gotmpl" +file-types = ["gotmpl"] +roots = [] +comment-token = "//" +language-server = { command = "gopls" } +indent = { tab-width = 2, unit = " " } + +[[grammar]] +name = "gotmpl" +source = { git = "https://github.com/dannylongeuay/tree-sitter-go-template", rev = "45acf03891557b80a45ac1897e2cca2e8b9cf0ff" } + [[language]] name = "gowork" scope = "source.gowork" diff --git a/runtime/queries/gotmpl/highlights.scm b/runtime/queries/gotmpl/highlights.scm new file mode 100644 index 000000000000..68a8ef87185d --- /dev/null +++ b/runtime/queries/gotmpl/highlights.scm @@ -0,0 +1,75 @@ +; Identifiers + +[ + (field) + (field_identifier) +] @property + +(variable) @variable + +; Function calls + +(function_call + function: (identifier) @function) + +(method_call + method: (selector_expression + field: (field_identifier) @function)) + +; Operators + +"|" @operator +":=" @operator + +; Builtin functions + +((identifier) @function.builtin + (#match? @function.builtin "^(and|call|html|index|slice|js|len|not|or|print|printf|println|urlquery|eq|ne|lt|ge|gt|ge)$")) + +; Delimiters + +"." @punctuation.delimiter +"," @punctuation.delimiter + +"{{" @punctuation.bracket +"}}" @punctuation.bracket +"{{-" @punctuation.bracket +"-}}" @punctuation.bracket +")" @punctuation.bracket +"(" @punctuation.bracket + +; Keywords + +"else" @keyword +"if" @keyword +"range" @keyword +"with" @keyword +"end" @keyword +"template" @keyword +"define" @keyword +"block" @keyword + +; Literals + +[ + (interpreted_string_literal) + (raw_string_literal) + (rune_literal) +] @string + +(escape_sequence) @string.special + +[ + (int_literal) + (float_literal) + (imaginary_literal) +] @number + +[ + (true) + (false) + (nil) +] @constant.builtin + +(comment) @comment +(ERROR) @error \ No newline at end of file diff --git a/runtime/queries/gotmpl/injections.scm b/runtime/queries/gotmpl/injections.scm new file mode 100644 index 000000000000..321c90add371 --- /dev/null +++ b/runtime/queries/gotmpl/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) From edec6155baf9a73ba991a057dcc7f46746c1c87f Mon Sep 17 00:00:00 2001 From: Daniel Longeuay Date: Mon, 18 Jul 2022 21:38:24 -0700 Subject: [PATCH 2/3] fix(tree-sitter): :bug: go template highlight scope selectors --- runtime/queries/gotmpl/highlights.scm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/runtime/queries/gotmpl/highlights.scm b/runtime/queries/gotmpl/highlights.scm index 68a8ef87185d..5921d161d9b7 100644 --- a/runtime/queries/gotmpl/highlights.scm +++ b/runtime/queries/gotmpl/highlights.scm @@ -3,7 +3,7 @@ [ (field) (field_identifier) -] @property +] @variable.other.member (variable) @variable @@ -63,13 +63,14 @@ (int_literal) (float_literal) (imaginary_literal) -] @number +] @constant.numeric.integer [ (true) (false) - (nil) -] @constant.builtin +] @constant.builtin.boolean + +(nil) @constant.builtin (comment) @comment -(ERROR) @error \ No newline at end of file +(ERROR) @error From 6785f161219de62079a98f0aa4bd44d30bb53245 Mon Sep 17 00:00:00 2001 From: dannylongeuay Date: Tue, 19 Jul 2022 17:04:52 -0700 Subject: [PATCH 3/3] chore(tree-sitter): :wrench: update go template grammar commit --- languages.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/languages.toml b/languages.toml index 1e0f8954a2cd..34b547bb38de 100644 --- a/languages.toml +++ b/languages.toml @@ -297,7 +297,7 @@ indent = { tab-width = 2, unit = " " } [[grammar]] name = "gotmpl" -source = { git = "https://github.com/dannylongeuay/tree-sitter-go-template", rev = "45acf03891557b80a45ac1897e2cca2e8b9cf0ff" } +source = { git = "https://github.com/dannylongeuay/tree-sitter-go-template", rev = "395a33e08e69f4155156f0b90138a6c86764c979" } [[language]] name = "gowork"