local ensure_installed = { "astro", "bash", "c", "css", "diff", "gitcommit", "gitignore", "go", "html", "javascript", "json", "lua", "luadoc", "markdown", "markdown_inline", "nix", "query", "rust", "ssh_config", "toml", "tsx", "typescript", "vim", "vimdoc", "yaml", "zig", } local function start(buf, lang) if not pcall(vim.treesitter.start, buf, lang) then return end vim.bo[buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end return { { -- Parsers and queries; highlighting itself is native (vim.treesitter.start) "nvim-treesitter/nvim-treesitter", branch = "main", lazy = false, build = ":TSUpdate", config = function() local ts = require("nvim-treesitter") ts.install(ensure_installed) vim.api.nvim_create_autocmd("FileType", { group = vim.api.nvim_create_augroup("treesitter-start", { clear = true }), callback = function(args) local lang = vim.treesitter.language.get_lang(args.match) if not lang then return end if vim.list_contains(ts.get_installed(), lang) then start(args.buf, lang) elseif vim.list_contains(ts.get_available(), lang) then ts.install(lang):await(vim.schedule_wrap(function() if vim.api.nvim_buf_is_valid(args.buf) then start(args.buf, lang) end end)) end end, }) end, }, }