tree-sitter-go-template
tree-sitter-go-template copied to clipboard
Suggested configuration brakes yaml highlighting.
Hello and very nice work, I was looking for something exactly like this.
As mentioned in the title, with the suggested configuration from the README, I no longer get syntax highlighting in yaml files. (yaml and not gotmpl files), however, helm templates work nicely (although only the context inside {{ }}
are highlighted).
require("nvim-treesitter.configs").setup({
ensure_installed = "all",
highlight = {
enable = true,
},
indent = {
enable = false,
},
})
local pc = require("nvim-treesitter.parsers").get_parser_configs()
pc.gotmpl = {
install_info = {
url = "https://github.com/ngalaiko/tree-sitter-go-template",
files = { "src/parser.c" },
},
filetype = "gotmpl",
used_by = { "gohtmltmpl", "gotexttmpl", "gotmpl", "yaml" },
}
By changing the used_by
from used_by = { "gohtmltmpl", "gotexttmpl", "gotmpl", "yaml" },
to used_by = { "gohtmltmpl", "gotexttmpl", "gotmpl" },
, yaml files get proper highlighting again but that brakes gotmpl files.
I'm experiencing the same issue, if I have "yaml" in the used_by list it breaks yaml parsing/highlighting, if I remove it then it breaks "gotmpl" parsing/highlighting.
@FotiadisM my current workaround is to add this injections query at
~/.config/nvim/after/queries/gotmpl/injections.scm
:
(text) @yaml
But that assumes you only template yaml with gotmpl. 🤷♂️
Hi!
Glad this helps. I've actually stopped using helm (which I mostly written this package for) on a daily basis, so I don't really keep up with the development of tree sitter, and nvim-tree-sitter.
If you (or anyone really) is interested in that, I suggest you fork this repo. It will probably not receive any attention from me in the near future. However, I will keep it open for reference.
I think I have something that is a step in the right direction but it still needs some more configuration. Here are the steps I have taken to enable yaml
and helm
syntax highlighting and LSP config.
I have my nvim config published publicly so please go and look at that for deeper context.
-
Install the
vim-helm
plugin > https://github.com/towolf/vim-helm This is a super simple plugin that just adds ahelm
filetype. You could even just copy paste the vim code into your own config, it really is very simple -
Install this
gotmpl
treesitter parser, but modify theused_by
option to havehelm
instead ofyaml
:
used_by = { "gohtmltmpl", "gotexttmpl", "gotmpl", "helm" },
- (this is optional) If you have LSP setup and you use
yamlls
, disable diagnostics on files with thishelm
filetype. This bit of lua code is taken from my own config. I use my standardon_attach()
function and then disable LSP Diagnostics if the filetype ishelm
:
lspconfig["yamlls"].setup({
capabilities = capabilities,
on_attach = function(client, bufnr)
on_attach(client, bufnr) -- run the standard on_attach function defined above
-- disable yamlls Diagnostics on helm files (this is dependent on "towolf/vim-helm")
-- without this the yamlls LSP server will show loads of errors in helm chart repositories
if vim.bo[bufnr].buftype ~= "" or vim.bo[bufnr].filetype == "helm" then
vim.diagnostic.disable()
end
It's not quite perfect, but it's certainly a step in the right direction and I think it works really well. I think your colorscheme will have some effect on the highlighting, I had to change mine to the very well supported nightfly to get the syntax highlighting to work properly.
Maybe I'll look more into tree-sitter development and see if I can get it over the finish line.
while the rest of the comment above ☝🏾 works like a charm, disabling diagnostics for a specific is more complicated than that, see https://github.com/neovim/neovim/issues/20745#issuecomment-1983998972