(lua) Add support for returns in local_functions
The extractor function being the same, I refactored the lua config file a little bit
This commit is contained in:
@@ -1,35 +1,4 @@
|
||||
return {
|
||||
-- Search for these nodes
|
||||
parent = { "function", "local_function", "local_variable_declaration", "field", "variable_declaration" },
|
||||
|
||||
-- Traverse down these nodes and extract the information as necessary
|
||||
data = {
|
||||
["function|local_function"] = {
|
||||
-- Get second child from the parent node
|
||||
["2"] = {
|
||||
-- It has to be of type "parameters"
|
||||
match = "parameters",
|
||||
|
||||
extract = function(node)
|
||||
local tree = {
|
||||
{ retrieve = "all", node_type = "identifier", extract = true },
|
||||
{ retrieve = "all", node_type = "spread", extract = true },
|
||||
}
|
||||
local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree)
|
||||
local res = neogen.utilities.extractors:extract_from_matched(nodes)
|
||||
|
||||
return {
|
||||
parameters = res.identifier,
|
||||
vararg = res.spread,
|
||||
}
|
||||
end,
|
||||
},
|
||||
},
|
||||
["local_variable_declaration|field|variable_declaration"] = {
|
||||
["2"] = {
|
||||
match = "function_definition",
|
||||
|
||||
extract = function(node)
|
||||
local common_function_extractor = function(node)
|
||||
local tree = {
|
||||
{
|
||||
retrieve = "first",
|
||||
@@ -50,7 +19,26 @@ return {
|
||||
vararg = res.spread,
|
||||
return_statement = res.return_statement,
|
||||
}
|
||||
end,
|
||||
end
|
||||
|
||||
return {
|
||||
-- Search for these nodes
|
||||
parent = { "function", "local_function", "local_variable_declaration", "field", "variable_declaration" },
|
||||
|
||||
data = {
|
||||
-- When the function is inside one of those
|
||||
["local_variable_declaration|field|variable_declaration"] = {
|
||||
["2"] = {
|
||||
match = "function_definition",
|
||||
|
||||
extract = common_function_extractor,
|
||||
},
|
||||
},
|
||||
-- When the function is in the root tree
|
||||
["function_definition|function|local_function"] = {
|
||||
["0"] = {
|
||||
|
||||
extract = common_function_extractor,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user