diff options
Diffstat (limited to 'lua/pi/snips/ft/go.lua')
| -rw-r--r-- | lua/pi/snips/ft/go.lua | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/lua/pi/snips/ft/go.lua b/lua/pi/snips/ft/go.lua index 9c3977f..4490e63 100644 --- a/lua/pi/snips/ft/go.lua +++ b/lua/pi/snips/ft/go.lua @@ -8,9 +8,6 @@ local i = ls.insert_node local rep = require("luasnip.extras").rep local fmt = require("luasnip.extras.fmt").fmt -local ts_locals = require "nvim-treesitter.locals" -local ts_utils = require "nvim-treesitter.ts_utils" - local get_node_text = vim.treesitter.get_node_text vim.treesitter.query.set( @@ -71,19 +68,28 @@ local handlers = { end, } +-- `nvim-treesitter.locals`/`ts_utils` no existen en la rama `main`; subimos a +-- mano por los padres del nodo bajo el cursor hasta la función que lo contiene. local function go_result_type(info) - local cursor_node = ts_utils.get_node_at_cursor() - local scope = ts_locals.get_scope_tree(cursor_node, 0) - local function_node - for _, v in ipairs(scope) do - if v:type() == "function_declaration" or v:type() == "method_declaration" or v:type() == "func_literal" then - function_node = v + local node = vim.treesitter.get_node() + while node do + local kind = node:type() + if kind == "function_declaration" or kind == "method_declaration" or kind == "func_literal" then + function_node = node break end + node = node:parent() + end + + if not function_node then + return end local query = vim.treesitter.query.get("go", "LuaSnip_Result") + if not query then + return + end for _, node in query:iter_captures(function_node, 0) do if handlers[node:type()] then return handlers[node:type()](node, info) |