ngalaiko / tree-sitter-go-template

Golang template grammar for tree-sitter
MIT License
72 stars 27 forks source link

Suggested configuration brakes yaml highlighting. #1

Open FotiadisM opened 2 years ago

FotiadisM commented 2 years ago

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" },
}

Screenshot from 2022-01-16 17-50-25

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.

reegnz commented 2 years ago

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.

reegnz commented 2 years ago

@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. 🤷‍♂️

ngalaiko commented 2 years ago

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.

Mo0rBy commented 7 months ago

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.

  1. Install the vim-helm plugin > https://github.com/towolf/vim-helm This is a super simple plugin that just adds a helm filetype. You could even just copy paste the vim code into your own config, it really is very simple

  2. Install this gotmpl treesitter parser, but modify the used_by option to have helm instead of yaml:

    used_by = { "gohtmltmpl", "gotexttmpl", "gotmpl", "helm" },
  3. (this is optional) If you have LSP setup and you use yamlls, disable diagnostics on files with this helm filetype. This bit of lua code is taken from my own config. I use my standard on_attach() function and then disable LSP Diagnostics if the filetype is helm:

        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.

FelipeLema commented 2 months ago

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