From 460d022cc1c25e94fa4f5e6feadadf60d6bb0abe Mon Sep 17 00:00:00 2001 From: Daniel Mathiot Date: Sat, 28 Aug 2021 15:28:14 +0200 Subject: [PATCH] (c) Add support for functions that return pointers --- lua/neogen/configurations/c.lua | 40 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/lua/neogen/configurations/c.lua b/lua/neogen/configurations/c.lua index 0888c2f..64c5d62 100644 --- a/lua/neogen/configurations/c.lua +++ b/lua/neogen/configurations/c.lua @@ -1,24 +1,30 @@ +local c_params = { + retrieve = "first", + node_type = "parameter_list", + subtree = { + { + retrieve = "all", + node_type = "parameter_declaration", + subtree = { + { retrieve = "first_recursive", node_type = "identifier", extract = true} + }, + }, + }, +} local c_function_extractor = function(node) local tree = { { retrieve = "first", node_type = "function_declarator", subtree = { - { - retrieve = "first", - node_type = "parameter_list", - subtree = { - { - retrieve = "all", - node_type = "parameter_declaration", - subtree = { - { retrieve = "first_recursive", node_type = "identifier", extract = true} - }, - }, - }, - }, + c_params, }, }, + { + retrieve = "first_recursive", + node_type = "function_declarator", + extract = true + }, { retrieve = "first", node_type = "compound_statement", @@ -26,11 +32,19 @@ local c_function_extractor = function(node) { retrieve = "first", node_type = "return_statement", extract = true }, }, }, + c_params } local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree) 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 subres = neogen.utilities.extractors:extract_from_matched(subnodes) + res = vim.tbl_deep_extend("keep", res, subres) + end + return { parameters = res.identifier, return_statement = res.return_statement,