go.nvim
go.nvim copied to clipboard
How to get highlights and injections to work with go-templates
I just managed to import gotmpl to my neovim config, It just took me 5 hours to do it! But thats not the point, Im very new to neovim. The only thing that I am yet to figure out is how to get highlightings and language injections (html, css, js) to work inside my go templates. If you know how , please let me know.
BTW: I posted almost the same issue here tree-sitter-go-template
here is my treesitter.lua config file settings
return {
-- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter',
build = ':TSUpdate',
opts = {
ensure_installed = {
'bash',
'c',
'diff',
'html',
'lua',
'luadoc',
'markdown',
'vim',
'vimdoc',
'css',
'go',
'gomod',
'gotmpl',
'gosum',
'gowork',
'yaml',
'python',
'json',
'javascript',
'sql',
'csv',
},
-- Autoinstall languages that are not installed
auto_install = true,
highlight = {
enable = true,
-- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
-- If you are experiencing weird indenting issues, add the language to
-- the list of additional_vim_regex_highlighting and disabled languages for indent.
additional_vim_regex_highlighting = { 'ruby' },
},
indent = { enable = true, disable = { 'ruby' } },
},
config = function(_, opts)
--
-- For detecting go template files
vim.filetype.add ( {
extension = {
gotmpl = 'gotmpl',
gohtml = 'gotmpl',
gohtmltmpl = 'gotmpl',
gohtxttmpl = 'gotmpl',
gohtexttmpl = 'gotmpl',
},
} )
local parser_configs = require('nvim-treesitter.parsers').get_parser_configs()
parser_configs['gotmpl'] = {
install_info = {
url = 'https://github.com/ngalaiko/tree-sitter-go-template',
files = { 'src/parser.c' },
},
filetype = 'gotmpl',
used_by = { 'gohtmltmpl', 'gotexttmpl', 'gotmpl', 'gotxttmpl', 'gohtml' },
}
-- For detecting go template files
--
require('nvim-treesitter.install').prefer_git = true
require('nvim-treesitter.configs').setup(opts)
end,
}