From 1161a7abdaff9830154531f62dbe75d8ee84029f Mon Sep 17 00:00:00 2001 From: Kirill Morozov Date: Wed, 8 Apr 2026 19:44:15 +0200 Subject: [PATCH 1/2] fix(neovim): migrate nvim-treesitter to main branch The master branch is frozen and incompatible with Neovim 0.12, which caused 'attempt to call method range (a nil value)' crashes from query_predicates.lua on every buffer open. The main branch is a full rewrite with a different API: the setup() mega-table is gone, parsers are installed via install(), and highlighting/indent are enabled per-buffer through a FileType autocmd. Parsers now compile locally via the tree-sitter CLI, which is added to the macOS brew package list as a prerequisite. nvim-treesitter-textobjects also switched to its main branch, where keymaps are wired manually via vim.keymap.set instead of the old nested config table. --- neovim/lazy-lock.json | 10 +- neovim/lua/plugins/tree-sitter.lua | 183 +++++++++--------- .../tasks/install-macos-packages.yml | 1 + 3 files changed, 99 insertions(+), 95 deletions(-) diff --git a/neovim/lazy-lock.json b/neovim/lazy-lock.json index 69c42d1..77a7fde 100644 --- a/neovim/lazy-lock.json +++ b/neovim/lazy-lock.json @@ -1,6 +1,6 @@ { "blink.cmp": { "branch": "main", "commit": "b19413d214068f316c78978b08264ed1c41830ec" }, - "catppuccin": { "branch": "main", "commit": "cb5665990a797b102715188e73c44c3931b3b42e" }, + "catppuccin": { "branch": "main", "commit": "605b4603797de970e9f3a4238c199c850da03186" }, "conform.nvim": { "branch": "master", "commit": "3543d000dafbc41cc7761d860cfdb24e82154f75" }, "fidget.nvim": { "branch": "main", "commit": "b61e8af9b8b68ee0ec7da5fb7a8c203aae854f2e" }, "fzf-lua": { "branch": "main", "commit": "47b85a25c0c0b2c20b4e75199ed01bb71e7814f5" }, @@ -8,12 +8,12 @@ "lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" }, "lazydev.nvim": { "branch": "main", "commit": "01bc2aacd51cf9021eb19d048e70ce3dd09f7f93" }, "lazygit.nvim": { "branch": "main", "commit": "a04ad0dbc725134edbee3a5eea29290976695357" }, - "log-highlight.nvim": { "branch": "main", "commit": "660306841f098c935c85ac3d4c66d67a64317495" }, + "log-highlight.nvim": { "branch": "main", "commit": "ca88628f6dd3b9bb46f9a7401669e24cf7de47a4" }, "mini.nvim": { "branch": "main", "commit": "a995fe9cd4193fb492b5df69175a351a74b3d36b" }, "neovim-ayu": { "branch": "master", "commit": "e5a9f0fa2918d6b5f57c21b3ac014314ee5e41c8" }, - "nvim-lspconfig": { "branch": "master", "commit": "5bfcc89fd155b4ffc02d18ab3b7d19c2d4e246a7" }, - "nvim-treesitter": { "branch": "main", "commit": "42fc28ba918343ebfd5565147a42a26580579482" }, - "nvim-treesitter-textobjects": { "branch": "master", "commit": "5ca4aaa6efdcc59be46b95a3e876300cfead05ef" }, + "nvim-lspconfig": { "branch": "master", "commit": "0203a9608d63eda57679b01e69f33a7b4c34b0d1" }, + "nvim-treesitter": { "branch": "main", "commit": "4916d6592ede8c07973490d9322f187e07dfefac" }, + "nvim-treesitter-textobjects": { "branch": "main", "commit": "851e865342e5a4cb1ae23d31caf6e991e1c99f1e" }, "plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" }, "rose-pine": { "branch": "main", "commit": "f01eac6eedf6197509dde8b66de0263207ee1877" }, "sort.nvim": { "branch": "main", "commit": "101fdda389ea5f9c6da6af13fe9d61d0a0aadff2" }, diff --git a/neovim/lua/plugins/tree-sitter.lua b/neovim/lua/plugins/tree-sitter.lua index d8d1eb6..fbf0cb1 100644 --- a/neovim/lua/plugins/tree-sitter.lua +++ b/neovim/lua/plugins/tree-sitter.lua @@ -3,10 +3,12 @@ return { { "fei6409/log-highlight.nvim", event = "BufRead *.log", opts = {} }, { "nvim-treesitter/nvim-treesitter", + branch = "main", build = ":TSUpdate", - config = function(_, opts) - ---@diagnostic disable-next-line: missing-fields - require("nvim-treesitter.configs").setup(opts) + lazy = false, + dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" }, + config = function() + -- Custom filetype detection for Helm and Go templates vim.filetype.add({ extension = { gotmpl = "gotmpl" }, pattern = { @@ -15,11 +17,9 @@ return { ["helmfile.*%.ya?ml"] = "helm", }, }) - end, - dependencies = { "nvim-treesitter/nvim-treesitter-textobjects" }, - event = { "BufNew", "BufRead" }, - opts = { - ensure_installed = { + + -- Parsers to install. Compiled locally via the tree-sitter CLI. + require("nvim-treesitter").install({ "bash", "comment", "diff", @@ -39,87 +39,90 @@ return { "vim", "vimdoc", "yaml", - }, - textobjects = { - select = { - enable = true, - lookahead = true, - keymaps = { - ["aa"] = { - query = "@parameter.outer", - desc = "Select around argument/parameter", - }, - ["ac"] = { - query = "@comment.outer", - desc = "Select around comment", - }, - ["af"] = { - query = "@function.outer", - desc = "Select around function", - }, - ["at"] = { - query = "@class.outer", - desc = "Select around type/class", - }, - ["ia"] = { - query = "@parameter.inner", - desc = "Select inside argument/parameter", - }, - ["ic"] = { - query = "@comment.inner", - desc = "Select inside comment", - }, - ["if"] = { - query = "@function.inner", - desc = "Select inside function", - }, - ["it"] = { - query = "@class.inner", - desc = "Select inside type/class", - }, - }, - }, - move = { - enable = true, - set_jumps = true, -- whether to set jumps in the jumplist - goto_next_start = { - ["]a"] = { - query = "@parameter.inner", - desc = "Next argument/parameter", - }, - ["]c"] = { query = "@comment.outer", desc = "Next comment" }, - ["]f"] = { query = "@function.outer", desc = "Next function" }, - ["]t"] = { query = "@class.outer", desc = "Next type/class" }, - }, - goto_previous_start = { - ["[a"] = { - query = "@parameter.inner", - desc = "Previous argument/parameter", - }, - ["[c"] = { query = "@comment.outer", desc = "Previous comment" }, - ["[f"] = { - query = "@function.outer", - desc = "Previous function", - }, - ["[t"] = { - query = "@class.outer", - desc = "Previous type/class", - }, - }, - }, - }, - -- Autoinstall languages that are not installed - auto_install = true, - highlight = { - enable = true, - -- Some languages depend on vim's regex highlighting system (such as - -- Ruby) for indent rules. If you are experiencing weird indenting - -- issues, add the language to the list of - -- additional_vim_regex_highlighting and disabled languages for indent. - additional_vim_regex_highlighting = { "ruby" }, - }, - indent = { enable = true, disable = { "ruby" } }, - }, - version = "*", + }) + + -- Filetypes to enable treesitter highlighting + indent for. + -- Note: parser names and filetype names sometimes differ + -- (e.g. `vimdoc` parser → `help` filetype, `bash` parser → `sh` filetype). + -- The `comment` parser has no filetype; it is used for injections only. + local filetypes = { + "bash", + "diff", + "dockerfile", + "elm", + "gitcommit", + "gleam", + "go", + "gotmpl", + "helm", + "help", + "json", + "lua", + "markdown", + "python", + "sh", + "terraform", + "toml", + "vim", + "yaml", + } + + vim.api.nvim_create_autocmd("FileType", { + pattern = filetypes, + callback = function() + vim.treesitter.start() + vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()" + end, + }) + end, + }, + { + "nvim-treesitter/nvim-treesitter-textobjects", + branch = "main", + lazy = false, + config = function() + require("nvim-treesitter-textobjects").setup({ + move = { set_jumps = true }, + }) + + local select = require("nvim-treesitter-textobjects.select") + local move = require("nvim-treesitter-textobjects.move") + + -- Selection keymaps: { lhs, query, desc } + local selects = { + { "aa", "@parameter.outer", "Select around argument/parameter" }, + { "ac", "@comment.outer", "Select around comment" }, + { "af", "@function.outer", "Select around function" }, + { "at", "@class.outer", "Select around type/class" }, + { "ia", "@parameter.inner", "Select inside argument/parameter" }, + { "ic", "@comment.inner", "Select inside comment" }, + { "if", "@function.inner", "Select inside function" }, + { "it", "@class.inner", "Select inside type/class" }, + } + for _, s in ipairs(selects) do + vim.keymap.set({ "x", "o" }, s[1], function() + select.select_textobject(s[2], "textobjects") + end, { desc = s[3] }) + end + + -- Movement keymaps: { lhs, query, direction, desc } + local moves = { + { "]a", "@parameter.inner", "next", "Next argument/parameter" }, + { "]c", "@comment.outer", "next", "Next comment" }, + { "]f", "@function.outer", "next", "Next function" }, + { "]t", "@class.outer", "next", "Next type/class" }, + { "[a", "@parameter.inner", "prev", "Previous argument/parameter" }, + { "[c", "@comment.outer", "prev", "Previous comment" }, + { "[f", "@function.outer", "prev", "Previous function" }, + { "[t", "@class.outer", "prev", "Previous type/class" }, + } + for _, m in ipairs(moves) do + local fn = m[3] == "next" and move.goto_next_start + or move.goto_previous_start + vim.keymap.set({ "n", "x", "o" }, m[1], function() + fn(m[2], "textobjects") + end, { desc = m[4] }) + end + end, }, } diff --git a/roles/development_machine/tasks/install-macos-packages.yml b/roles/development_machine/tasks/install-macos-packages.yml index 904ebad..ccd70de 100644 --- a/roles/development_machine/tasks/install-macos-packages.yml +++ b/roles/development_machine/tasks/install-macos-packages.yml @@ -13,6 +13,7 @@ - neovim - ripgrep - starship + - tree-sitter - uv - vim - yq From fb2992e5bd7b1c574e79b9ad00b8b7e3ff001f75 Mon Sep 17 00:00:00 2001 From: Kirill Morozov Date: Wed, 8 Apr 2026 19:48:04 +0200 Subject: [PATCH 2/2] fix: install tree-sitter-cli package --- roles/development_machine/tasks/install-macos-packages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/development_machine/tasks/install-macos-packages.yml b/roles/development_machine/tasks/install-macos-packages.yml index ccd70de..1a30552 100644 --- a/roles/development_machine/tasks/install-macos-packages.yml +++ b/roles/development_machine/tasks/install-macos-packages.yml @@ -13,7 +13,7 @@ - neovim - ripgrep - starship - - tree-sitter + - tree-sitter-cli - uv - vim - yq