From 2ede98c4b4275cc2176836347b7c921a7f018d72 Mon Sep 17 00:00:00 2001 From: Daniel Longeuay <93006157+dannylongeuay@users.noreply.github.com> Date: Mon, 25 Jul 2022 18:17:28 -0700 Subject: [PATCH] feat(tree-sitter): :sparkles: add go template support (#3091) * feat(tree-sitter): :sparkles: add go template support * fix(tree-sitter): :bug: go template highlight scope selectors * chore(tree-sitter): :wrench: update go template grammar commit --- book/src/generated/lang-support.md | 1 + languages.toml | 14 +++++ runtime/queries/gotmpl/highlights.scm | 76 +++++++++++++++++++++++++++ runtime/queries/gotmpl/injections.scm | 2 + 4 files changed, 93 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 a5d286d7f..6b938def1 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 c2e0549f3..1eaec8ddc 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 = "395a33e08e69f4155156f0b90138a6c86764c979" } + [[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 000000000..5921d161d --- /dev/null +++ b/runtime/queries/gotmpl/highlights.scm @@ -0,0 +1,76 @@ +; Identifiers + +[ + (field) + (field_identifier) +] @variable.other.member + +(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) +] @constant.numeric.integer + +[ + (true) + (false) +] @constant.builtin.boolean + +(nil) @constant.builtin + +(comment) @comment +(ERROR) @error diff --git a/runtime/queries/gotmpl/injections.scm b/runtime/queries/gotmpl/injections.scm new file mode 100644 index 000000000..321c90add --- /dev/null +++ b/runtime/queries/gotmpl/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment"))