From 4755deffda8eeb0ceed53b535cce29f0e29a640a Mon Sep 17 00:00:00 2001 From: zach-wahrer Date: Tue, 31 Mar 2026 07:46:43 -0600 Subject: [PATCH] fix treesitter node recursion for nvim v0.12 --- lua/go/ts/nodes.lua | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/lua/go/ts/nodes.lua b/lua/go/ts/nodes.lua index 5b1188fe6..bb7f90624 100644 --- a/lua/go/ts/nodes.lua +++ b/lua/go/ts/nodes.lua @@ -27,6 +27,27 @@ if parse == nil then parse = vim.treesitter.query.parse_query end +local function as_tsnode(node) + if node == nil then + return nil + end + + if type(node) == 'table' then + if #node < 1 then + return nil + end + node = node[1] + end + + if pcall(function() + return node:range() + end) then + return node + end + + return nil +end + if _GO_NVIM_CFG and not _GO_NVIM_CFG.verbose_ts then ulog = function() end end @@ -99,6 +120,11 @@ M.get_nodes = function(query, lang, defaults, bufnr) local type = 'nil' local name = 'nil' locals.recurse_local_nodes(match, function(_, node, path) + node = as_tsnode(node) + if node == nil then + return + end + local idx = string.find(path, '.', 1, true) local op = string.sub(path, idx + 1, #path) @@ -175,6 +201,11 @@ M.get_all_nodes = function(query, lang, defaults, bufnr, pos_row, pos_col, ntype ulog(match) locals.recurse_local_nodes(match, function(_, node, path) + node = as_tsnode(node) + if node == nil then + return + end + -- local idx = string.find(path, ".", 1, true) -- The query may return multiple nodes, e.g. -- (type_declaration (type_spec name:(type_identifier)@type_decl.name type:(type_identifier)@type_decl.type))@type_decl.declaration