Skip to content

Treesitter

Blak uses the main branch of nvim-treesitter — its installer API downloads and builds language grammars; Neovim provides highlighting.

Setup: lua/blak/core/treesitter.lua. Spec: lua/blak/plugins/editor.lua.

treesitter = {
ensure_installed = {
"bash", "c", "diff", "html", "json", "lua", "luadoc",
"markdown", "markdown_inline", "query", "regex", "toml",
"vim", "vimdoc", "yaml",
},
}

Language extras add to this list automatically:

Extra Adds
lang.typescript javascript, typescript, tsx, jsdoc, json
lang.typescript-tsgo javascript, typescript, tsx, jsdoc, json
lang.python python
lang.python-pro python, requirements
lang.rust rust, toml
lang.go go, gomod, gosum, gowork
lang.markdown markdown, markdown_inline

.jsonc files reuse the json parser — nvim-treesitter no longer ships a separate jsonc grammar — so JSONC highlighting works without its own parser.

:BlakTreesitterInstall

Calls nvim-treesitter.install() with your merged list and notifies on completion. The compile step needs a C compiler and tree-sitter on $PATH — Blak ships tree-sitter-cli in the default Mason set, so on a first launch :BlakToolsInstall followed by :BlakTreesitterInstall is enough.

You can also install one parser at a time:

:lua require("nvim-treesitter").install({ "zig" })

Treesitter only starts on a buffer when:

  1. Its filetype has an installed parser.
  2. Its line count is at most performance.max_treesitter_lines (default 10000).

The check happens on FileType:

-- lua/blak/core/treesitter.lua, abbreviated
vim.api.nvim_create_autocmd("FileType", {
callback = function(args)
if vim.api.nvim_buf_line_count(args.buf) > max_lines then return end
if pcall(vim.treesitter.start, args.buf) then
vim.bo[args.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end
end,
})

So opening a 200k-line log file won’t grind to a halt — treesitter just doesn’t attach.

return {
performance = {
max_treesitter_lines = 25000,
},
}

Either in user.lua:

return {
treesitter = {
ensure_installed = { "bash", "lua", "zig", "yaml" },
},
}

Lists are replaced wholesale — write out everything you want, or add it via an extra so the merge is additive.

Or as an extra:

-- lua/blak/extras/lang/zig.lua
return {
id = "lang.zig",
label = "Zig",
treesitter = { "zig" },
mason = { "zls" },
lsp = { servers = { zls = {} } },
}

Blak sets indentexpr to nvim-treesitter’s indent function on every buffer that gets a parser. If you want a language-specific indent, override via filetype autocmd in user.lua.

:checkhealth nvim-treesitter " native checker
:Inspect " show the tree at cursor
:InspectTree " open the parse tree