diff --git a/lua/neogen.lua b/lua/neogen.lua index a49a79c..a42e716 100644 --- a/lua/neogen.lua +++ b/lua/neogen.lua @@ -184,6 +184,7 @@ neogen.setup = function(opts) java = require("neogen.configurations.java"), rust = require("neogen.configurations.rust"), cs = require("neogen.configurations.csharp"), + php = require("neogen.configurations.php"), }, }) diff --git a/lua/neogen/configurations/php.lua b/lua/neogen/configurations/php.lua new file mode 100644 index 0000000..68a663a --- /dev/null +++ b/lua/neogen/configurations/php.lua @@ -0,0 +1,84 @@ +return { + parent = { + type = { "property_declaration", "const_declaration", "foreach_statement" }, + func = { "function_definition" }, + }, + data = { + type = { + ["property_declaration|const_declaration|foreach_statement"] = { + ["0"] = { + extract = function(node) + local tree = { + { node_type = "property_element", retrieve = "all", extract = true }, + } + local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree) + local res = neogen.utilities.extractors:extract_from_matched(nodes) + return res + end, + }, + }, + }, + func = { + ["function_definition"] = { + ["0"] = { + extract = function(node) + local tree = { + { + node_type = "formal_parameters", + retrieve = "first", + subtree = { + { + node_type = "simple_parameter", + retrieve = "all", + subtree = { + { + node_type = "variable_name", + retrieve = "all", + extract = true, + }, + }, + }, + }, + }, + { + node_type = "compound_statement", + retrieve = "first", + subtree = { + { + retrieve = "first", + node_type = "return_statement", + recursive = true, + extract = true, + }, + }, + }, + } + local nodes = neogen.utilities.nodes:matching_nodes_from(node, tree) + local res = neogen.utilities.extractors:extract_from_matched(nodes) + return res + end, + }, + }, + }, + }, + template = { + annotation_convention = "phpdoc", + use_default_comment = false, + + phpdoc = { + { nil, "/** @var $1 */", { no_results = true, type = { "type" } } }, + + { nil, "/**", { no_results = true, type = { "func" } } }, + { nil, " * $1", { no_results = true, type = { "func" } } }, + { nil, "*/", { no_results = true, type = { "func" } } }, + + { nil, "/**", { type = { "type", "func" } } }, + { nil, " * $1", { type = { "func" } } }, + { nil, " *", { type = { "func" } } }, + { "property_element", " * @var $1", { type = { "type" } } }, + { "variable_name", " * @param $1 %s $1", { type = { "func" } } }, + { "return_statement", " * @return $1", { type = { "func" } } }, + { nil, "*/", { type = { "type", "func" } } }, + }, + }, +}