Skip to content

Commit

Permalink
feat(tree-sitter): ✨ add go template support (#3091)
Browse files Browse the repository at this point in the history
* feat(tree-sitter): ✨ add go template support

* fix(tree-sitter): 🐛 go template highlight scope selectors

* chore(tree-sitter): 🔧 update go template grammar commit
  • Loading branch information
dannylongeuay authored Jul 26, 2022
1 parent d4a5413 commit 2ede98c
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 0 deletions.
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
| glsl |||| |
| go |||| `gopls` |
| gomod || | | `gopls` |
| gotmpl || | | `gopls` |
| gowork || | | `gopls` |
| graphql || | | |
| hare || || |
Expand Down
14 changes: 14 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
76 changes: 76 additions & 0 deletions runtime/queries/gotmpl/highlights.scm
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions runtime/queries/gotmpl/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))

0 comments on commit 2ede98c

Please sign in to comment.