nvim/lua/plugins/treesitter.lua
2026-04-22 10:34:11 -03:00

71 lines
1.5 KiB
Lua

return {
'nvim-treesitter/nvim-treesitter',
branch = 'main',
build = ':TSUpdate',
config = function()
local ts = require('nvim-treesitter')
local parsers = {
'lua',
'vim',
'vimdoc',
'rust',
'typescript',
'tsx',
'javascript',
'jsx',
'html',
'css',
'scss',
'json',
'sql',
'nix',
'bash',
'yaml',
'dockerfile',
'markdown',
'markdown_inline',
'c',
'cpp',
'python',
'toml',
'astro',
'vue',
'java',
'angular',
'wgsl',
}
for _, parser in ipairs(parsers) do
ts.install(parser)
end
-- Detect Angular HTML templates and set filetype to htmlangular
vim.api.nvim_create_autocmd('FileType', {
pattern = 'html',
callback = function(ev)
local root = vim.fs.root(ev.buf, { 'angular.json' })
if root then
vim.bo[ev.buf].filetype = 'htmlangular'
end
end,
})
-- Filetypes whose name differs from the parser name
local ft_to_parser = {
typescriptreact = 'tsx',
javascriptreact = 'jsx',
htmlangular = 'angular',
}
vim.api.nvim_create_autocmd('FileType', {
callback = function(ev)
local ft = ev.match
local lang = ft_to_parser[ft] or ft
if pcall(vim.treesitter.start, ev.buf, lang) then
vim.bo[ev.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
end
end,
})
end,
}