From c575186ff90b1ea12e79f7549b9341fd0b52b891 Mon Sep 17 00:00:00 2001 From: danymat Date: Tue, 25 Jan 2022 21:42:46 +0100 Subject: [PATCH] fix(lua) Offset handling for local functions --- lua/neogen/locators/lua.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lua/neogen/locators/lua.lua b/lua/neogen/locators/lua.lua index aedb076..bd11bd6 100644 --- a/lua/neogen/locators/lua.lua +++ b/lua/neogen/locators/lua.lua @@ -8,5 +8,18 @@ return function(node_info, nodes_to_match) node_info.current = ts_utils.get_node_at_cursor() end - return neogen.default_locator(node_info, nodes_to_match) + local found_node = neogen.default_locator(node_info, nodes_to_match) + + -- for functions like "local x = function ()...end" the assignment_statement + -- will be fetched just before the variable_declaration + -- So we need to make sure to return the variable_declaration instead + -- otherwise it'll mess up in our annotation placement + if found_node and found_node:type() == "assignment_statement" then + local parent = found_node:parent() + if parent and parent:type() == "variable_declaration" then + return parent + end + end + + return found_node end