これを入れた
GitHub
GitHub - ngalaiko/tree-sitter-go-template: Golang template grammar for tree-sitter
Golang template grammar for tree-sitter. Contribute to ngalaiko/tree-sitter-go-template development by creating an account on GitHub.
text/template の nvim-treesitter 向けのパーサー
セットアップ
公式の通りだがメモしておく
- parserに追加したあと、
:TSInstallFromGrammar gotmpl
- gotmplを検知したらfiletypeに設定されるようにする
luaで書く場合はこんな感じに
- queries に追加する
~/.config/nvim/queries/gotmpl/injections.scm
(text) @yaml
~/.config/nvim/queries/gotmpl/highlights.scm
; Identifiers
[
(field)
(field_identifier)
] @property
(variable) @variable
; Function calls
(function_call
function: (identifier) @function)
(method_call
method: (selector_expression
field: (field_identifier) @method))
; 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"
"else if"
"if"
"with"
] @conditional
[
"range"
"end"
"template"
"define"
"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)
] @boolean
[
(nil)
] @constant.builtin
(comment) @comment
(ERROR) @error