From 08d1df4643915a7715a58c0d24d292f89a3b5f04 Mon Sep 17 00:00:00 2001 From: Bryan Ramos Date: Thu, 30 Apr 2026 10:27:00 -0400 Subject: [PATCH] fix(treesitter): migrate to neovim 0.12 APIs --- lua/plugins/lsp.lua | 82 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 67 insertions(+), 15 deletions(-) diff --git a/lua/plugins/lsp.lua b/lua/plugins/lsp.lua index c31339b..5b1e8d5 100644 --- a/lua/plugins/lsp.lua +++ b/lua/plugins/lsp.lua @@ -18,13 +18,40 @@ local mason_ensure_installed = { "yamlls", -- YAML } +local treesitter_parsers = { + "lua", + "c", + "cpp", + "python", + "nix", + "rust", + "bash", + "markdown", + "html", + "html_tags", + "javascript", + "ecma", + "jsx", + "css", + "vim", + "git_config", + "git_rebase", + "gitattributes", + "gitcommit", + "gitignore", +} + return { { - "nvim-treesitter/nvim-treesitter", + "neovim-treesitter/nvim-treesitter", + name = "nvim-treesitter", + dependencies = { "neovim-treesitter/treesitter-parser-registry" }, + lazy = false, build = ":TSUpdate", - config = function() - require('nvim-treesitter.configs').setup({ - ensure_installed = { + init = function() + vim.api.nvim_create_autocmd("FileType", { + group = vim.api.nvim_create_augroup("config_treesitter", { clear = true }), + pattern = { "lua", "c", "cpp", @@ -35,22 +62,47 @@ return { "markdown", "html", "javascript", + "javascriptreact", "css", - "vim", - - "git_config", - "git_rebase", + "gitconfig", + "gitrebase", "gitattributes", "gitcommit", - "gitignore" + "gitignore", }, - auto_install = true, - sync_install = true, - highlight = { - enable = true, - } + callback = function(event) + if pcall(vim.treesitter.start, event.buf) then + vim.wo.foldexpr = "v:lua.vim.treesitter.foldexpr()" + vim.wo.foldmethod = "expr" + vim.bo[event.buf].indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end + end, }) + end, + config = function() + require("nvim-treesitter").setup() + + local installed = require("nvim-treesitter.config").get_installed() + local missing = vim.iter(treesitter_parsers) + :filter(function(parser) + return not vim.tbl_contains(installed, parser) + end) + :totable() + + if #missing == 0 then + return + end + + if vim.fn.executable("tree-sitter") == 0 then + vim.notify_once( + "tree-sitter CLI is required to install or update parsers; enter a Nix shell that provides tree-sitter before running :TSUpdate", + vim.log.levels.WARN + ) + return + end + + require("nvim-treesitter").install(missing) end }, @@ -302,7 +354,7 @@ return { { "taproot-wizards/bitcoin-script-hints.nvim", - dependencies = { "nvim-treesitter/nvim-treesitter" }, + dependencies = { "nvim-treesitter" }, config = function() require("bitcoin-script-hints").setup() end