vim.api.nvim_create_autocmd("PackChanged", { callback = function(ev) if ev.data.spec.name ~= "nvim-treesitter" then return end if ev.data.kind ~= "install" and ev.data.kind ~= "update" then return end if not ev.data.active then vim.cmd.packadd("nvim-treesitter") end vim.cmd("TSUpdate") end, }) return { src = "https://github.com/nvim-treesitter/nvim-treesitter", name = "nvim-treesitter", version = "main", spec = { "nvim-treesitter", lazy = true, beforeAll = function() vim.api.nvim_create_autocmd("FileType", { callback = function(ev) if ev.match == "alpha" or vim.bo[ev.buf].buftype == "nofile" then return end local lang = vim.treesitter.language.get_lang(ev.match) if not lang then return end require("lz.n").trigger_load("nvim-treesitter") local ts = require("nvim-treesitter") local function start() if not vim.api.nvim_buf_is_valid(ev.buf) then return end if pcall(vim.treesitter.start, ev.buf, lang) then vim.bo[ev.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" end end if vim.list_contains(ts.get_installed(), lang) then start() elseif vim.list_contains(ts.get_available(), lang) then ts.install(lang):await(vim.schedule_wrap(start)) end end, }) end, after = function() require("nvim-treesitter").install({ "lua", "vim", "vimdoc", "query", "markdown", "markdown_inline", "bash", "python", "javascript", "typescript", "html", "css", }) end, }, }