From d09756d93c556507b60a3351480afc0800ca8e66 Mon Sep 17 00:00:00 2001 From: danymat Date: Sun, 9 Jan 2022 18:52:41 +0100 Subject: [PATCH] fix(c/cpp) Do not show `@return` if void function (#32) --- lua/neogen/configurations/c.lua | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lua/neogen/configurations/c.lua b/lua/neogen/configurations/c.lua index c13b8d9..ad58cf1 100644 --- a/lua/neogen/configurations/c.lua +++ b/lua/neogen/configurations/c.lua @@ -68,7 +68,7 @@ local c_function_extractor = function(node) local res = neogen.utilities.extractors:extract_from_matched(nodes) if nodes.function_declarator then - local subnodes = neogen.utilities.nodes:matching_nodes_from(nodes.function_declarator[1], tree) + local subnodes = neogen.utilities.nodes:matching_nodes_from(nodes.function_declarator[1]:parent(), tree) local subres = neogen.utilities.extractors:extract_from_matched(subnodes) res = vim.tbl_deep_extend("keep", res, subres) end @@ -77,13 +77,16 @@ local c_function_extractor = function(node) --- If so, return { true } as we don't need to properly know the content of the node for the template --- @return table? local has_return_statement = function() + if res.primitive_type and res.primitive_type[1] == "void" then + return + end if res.return_statement then -- function implementation return res.return_statement elseif res.function_declarator and (res.primitive_type or res.type_identifier) then if res.type_identifier then return { true } - elseif res.primitive_type[1] ~= "void" or res.pointer_declarator then + elseif res.primitive_type and res.primitive_type[1] ~= "void" or res.pointer_declarator then -- function prototype return { true } end