-- Installes the nvim-treesitter plugin. vim.pack.add({ "https://github.com/nvim-treesitter/nvim-treesitter", }, { confirm = false }) -- Installs parsers. require("nvim-treesitter").install({ -- Bundled parsers. "c", "lua", "markdown", "markdown_inline", "query", "vim", "vimdoc", -- Extra parsers. "bash", "diff", "git_rebase", "gitcommit", "go", "json", "python", "vhdl", }) -- Runs `:TSUpdate` when the nvim-treesitter plugin is installed or -- updated. vim.api.nvim_create_autocmd({ "PackChanged" }, { callback = function(ev) if ev.data.spec.name == "nvim-treesitter" and (ev.data.kind == "install" or ev.data.kind == "update") then vim.schedule(function() vim.cmd.TSUpdate() end) end end, }) -- Enables treesitter on supported filetypes. vim.api.nvim_create_autocmd("FileType", { callback = function(ev) if pcall(vim.treesitter.start) then -- If treesitter was enabled and folding queries are installed, -- use the queries for folding. if vim.treesitter.query.get(ev.match, "folds") then vim.wo[0][0].foldexpr = "v:lua.vim.treesitter.foldexpr()" vim.wo[0][0].foldmethod = "expr" end end end, })