diff options
| author | Matt Turner <mattst88@gmail.com> | 2026-11-11 19:16:33 -0500 |
|---|---|---|
| committer | Matt Turner <mattst88@gmail.com> | 2026-11-11 19:16:33 -0500 |
| commit | 2b1a30ca319e726bdeac84b038820e05f148d885 (patch) | |
| tree | 78fe077efadac405354dc3e8da74b8f7f3fe730d | |
| parent | a471289b41250d0ef805aff481aebf134ebc6719 (diff) | |
nvim: switch nvim-treesitter to the main branch
The master branch is frozen and broken on Neovim 0.12: opening a buffer
fails in vim.treesitter.get_range with "attempt to call method 'range'
(a nil value)".
The main branch drops the configs module, so install parsers with
install() and enable highlighting and indent from a FileType autocmd.
Skip buffers bigfile.nvim has flagged, since its treesitter feature
relies on nvim-treesitter.configs.
Drop nvim-treesitter-textobjects, which was never configured, and the
unused packer-style run hook and context_commentstring option.
Building parsers now requires the tree-sitter CLI.
| -rw-r--r-- | nvim/.config/nvim/lua/plugins/treesitter.lua | 86 |
1 files changed, 49 insertions, 37 deletions
diff --git a/nvim/.config/nvim/lua/plugins/treesitter.lua b/nvim/.config/nvim/lua/plugins/treesitter.lua index 1fbb3e7..7331d2b 100644 --- a/nvim/.config/nvim/lua/plugins/treesitter.lua +++ b/nvim/.config/nvim/lua/plugins/treesitter.lua @@ -2,45 +2,57 @@ -- and manual language installations, this plugin. -- Without this, treesitter file types need to manually installed and updated. +-- +-- This uses the `main` branch. The old `master` branch is frozen and does not +-- work with Neovim 0.12. The `main` branch needs the tree-sitter CLI +-- (dev-util/tree-sitter-cli) to build parsers, and does not support +-- lazy-loading. +local languages = { + "bash", + "c", + "cmake", + "cpp", + "git_config", + "gitattributes", + "gitcommit", + "gitignore", + "ini", + "json5", + "lua", + "make", + "markdown", + "meson", + "ninja", + "python", + "rust", + "toml", + "vim", + "yaml", +} + return { "nvim-treesitter/nvim-treesitter", - dependencies = { - "nvim-treesitter/nvim-treesitter-textobjects", - }, + branch = "main", + lazy = false, + build = ":TSUpdate", + config = function() + require("nvim-treesitter").install(languages) - build = function() - require("nvim-treesitter.install").update({ with_sync = true })() - end, - run = function() - local ts_update = require("nvim-treesitter.install").update({ with_sync = true }) - ts_update() + vim.api.nvim_create_autocmd("FileType", { + group = vim.api.nvim_create_augroup("treesitter", { clear = true }), + callback = function(args) + -- Set by bigfile.nvim for files over its size limit. + if vim.b[args.buf].bigfile_disable_treesitter then + return + end + -- Returns false (or errors) if no parser is installed for + -- this filetype. + if not pcall(vim.treesitter.start, args.buf) then + return + end + vim.bo[args.buf].indentexpr = + "v:lua.require'nvim-treesitter'.indentexpr()" + end, + }) end, - event = "BufReadPost", - opts = { - highlight = { enable = true }, - indent = { enable = true }, - context_commentstring = { enable = true, enable_autocmd = false }, - ensure_installed = { - "bash", - "c", - "cmake", - "cpp", - "git_config", - "gitattributes", - "gitcommit", - "gitignore", - "ini", - "json5", - "lua", - "make", - "markdown", - "meson", - "ninja", - "python", - "rust", - "toml", - "vim", - "yaml", - }, - }, } |
