issue #424; neovim is deprecating non-treesitter based syntax highlighting, so it is this plugin

pull/448/head
ray-x 2 months ago
parent 7a52a370ab
commit 05ba8a9032

@ -37,13 +37,14 @@ The plugin covers most features required for a gopher.
- Inlay hints: gopls (version 0.9.x or greater) inlay hints; version 0.10.x inlay hints are enabled by default.
- luasnip: go.nvim included a feature rich luasnips you definitally need to try.
- Treesitter highlight injection: go.nvim included a treesitter highlight injection for SQL and JSON.
- Treesitter also injects highlight for `go template`, `gohtmltmpl`
- Generate return value for current function
- Generate go file with template
- Generate go struct from json
## Installation
Use your favorite package manager to install. The dependency `treesitter` (and optionally, treesitter-objects)
Use your favorite package manager to install. The dependency ` treesitter ` (and optionally, treesitter-objects)
should be installed the first time you use it.
Also Run `TSInstall go` to install the go parser if not installed yet.
`sed` is recommended to run this plugin.
@ -1167,6 +1168,39 @@ require('lspconfig').gopls.setup(cfg)
```
## Highlighting for gomod, gosum, gohtmltmpl, gotmpl, gotexttmpl
You can install treesitter parser for gomod and gosum
```vim
:TSInstall gomod gosum
```
As for go template, the plugin has not been merge to treeistter master yet, you need to install
[treesitter-go-template](https://github.com/ngalaiko/tree-sitter-go-template)
```lua
local parser_config = require'nvim-treesitter.parsers'.get_parser_configs()
parser_config.gotmpl = {
install_info = {
url = "https://github.com/ngalaiko/tree-sitter-go-template",
files = {"src/parser.c"}
},
filetype = "gotmpl",
used_by = {"gohtmltmpl", "gotexttmpl", "gotmpl", "yaml"}
}
```
And run
```vim
:TSInstall gotmpl
```
The plugin injects the tmpl to html so you should see this:
<img width="453" alt="image" src="https://gist.github.com/assets/1681295/b6bcd1b3-94c4-4b34-9098-4cbd1ab8669e">
## Integrate null-ls
### The plugin provides:

@ -0,0 +1,2 @@
(module_path) @namespace
(version) @keyword

@ -0,0 +1,85 @@
; Copyright: https://github.com/ngalaiko/tree-sitter-go-template
; 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

@ -0,0 +1,9 @@
(text) @yaml
((text) @injection.content
(#set! injection.language "html")
(#set! injection.combined))
((text) @injection.content
(#set! injection.language "javascript")
(#set! injection.combined))

@ -1,18 +0,0 @@
" this file is copied from vim-go
if exists("b:current_syntax")
finish
endif
if !exists("g:main_syntax")
let g:main_syntax = 'html'
endif
runtime! syntax/gotexttmpl.vim
runtime! syntax/html.vim
unlet b:current_syntax
syn cluster htmlPreproc add=gotplAction,goTplComment
let b:current_syntax = "gohtmltmpl"
" vim: sw=2 ts=2 et

@ -1,36 +0,0 @@
" Copyright 2011 The Go Authors. All rights reserved.
" Use of this source code is governed by a BSD-style
" license that can be found in the LICENSE file.
"
" gotexttmpl.vim: Vim syntax file for Go templates.
" Quit when a (custom) syntax file was already loaded
" a modified version of gotexttmpl.vim
if exists("b:current_syntax")
finish
endif
runtime! syntax/go.vim
unlet b:current_syntax
" Token groups
syn cluster gotplLiteral contains=goString,goRawString,goCharacter,@goInt,goFloat,goImaginary
syn keyword gotplControl contained if else end range with template
syn keyword gotplFunctions contained and html index js len not or print printf println urlquery eq ne lt le gt ge
syn match gotplVariable contained /\$[a-zA-Z0-9_]*\>/
syn match goTplIdentifier contained /\.[^[:blank:]}]\+\>/
hi def link gotplControl Keyword
hi def link gotplFunctions Function
hi def link goTplVariable Special
syn region gotplAction start="{{" end="}}" contains=@gotplLiteral,gotplControl,gotplFunctions,gotplVariable,goTplIdentifier display
syn region goTplComment start="{{\(- \)\?/\*" end="\*/\( -\)\?}}" display
hi def link gotplAction PreProc
hi def link goTplComment Comment
let b:current_syntax = "gotexttmpl"
" vim: sw=2 ts=2 et
Loading…
Cancel
Save