Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get highlights and injections to work with go-templates #468

Open
behnamgolds opened this issue May 29, 2024 · 0 comments
Open

How to get highlights and injections to work with go-templates #468

behnamgolds opened this issue May 29, 2024 · 0 comments

Comments

@behnamgolds
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant