Files
neogen/lua/neogen/configurations/lua.lua
Daniel Mathiot ce765cc43c (lua) Add support for returns in local_functions
The extractor function being the same, I refactored the lua config file
a little bit
2021-08-25 12:22:36 +02:00

65 lines
1.9 KiB
Lua

local common_function_extractor = function(node)
local tree = {
{
retrieve = "first",
node_type = "parameters",
subtree = {
{ retrieve = "all", node_type = "identifier", extract = true },
{ retrieve = "all", node_type = "spread", extract = true },
},
},
{ retrieve = "first", node_type = "return_statement", 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,
return_statement = res.return_statement,
}
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,
},
},
},
-- Custom lua locator that escapes from comments
locator = require("neogen.locators.lua"),
-- Use default granulator and generator
granulator = nil,
generator = nil,
template = {
-- Which annotation convention to use
annotation_convention = "emmylua",
emmylua = {
{ nil, "- " },
{ nil, "- ", { no_results = true } },
{ "parameters", "- @param %s any" },
{ "vararg", "- @vararg any" },
{ "return_statement", "- @return any" },
},
},
}