danderson / tree-sitter-templ

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

tree-sitter-templ

A tree-sitter grammar for Templ.

Using this with Neovim

To use this parser for syntax highlighting in Neovim, you need nvim-treesitter. It is highly recommended you go through nvim-treesitter's quickstart, but in any case a minimal configuration to enable syntax highlighting looks like this:

require'nvim-treesitter.configs'.setup {
  highlight = {
    enable = true,
    additional_vim_regex_highlighting = false,
  },
}

Once nvim-treesitter is installed you need to install the parser with the command :TSInstall templ.

You can check its status with :checkhealth, you should see something like this:

nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v18.16.1 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (GCC) 13.1.1 20230614 (Red Hat 13.1.1-4)
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features         H L F I J
  - templ               ✓ . . . ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang} ~

Finally you also need to add register the templ filetype:

vim.filetype.add({
    extension = {
        templ = "templ",
    },
})

Finally you can open a templ file and run :InspectTree to see the parse tree.

Contributing

The official tree-sitter documentation for creating a parser contains everything you need to start contributing to this parser.

To make it slightly easier, we use a Justfile to simplify some things:

  • just test [filter...] to run tests
  • just gen to only generate the parser
  • just build to generate then build the parser

If you want to modify the parser, make sure to add a test or modify an existnig one in the corpus directory.

About

License:MIT License


Languages

Language:C 44.5%Language:JavaScript 33.4%Language:Rust 9.0%Language:Scheme 6.1%Language:Lua 2.6%Language:C++ 2.4%Language:Python 0.9%Language:Just 0.8%Language:Vim Script 0.2%