ref!: Extract template codes into template dir
I possibly introduced some bugs in the process, please open an issue if so. - This is an attempt to refactor the code and provide re-use of templates (for example, doxygen or jsdoc) - I standardized the exposed returned nodes for a template (you can view it by going to lua/neogen/types/template.lua)
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
local default_locator = require("neogen.locators.default")
|
local default_locator = require("neogen.locators.default")
|
||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
local c_params = {
|
local c_params = {
|
||||||
retrieve = "first",
|
retrieve = "first",
|
||||||
@@ -104,10 +106,9 @@ local c_function_extractor = function(node)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
parameters = res.identifier,
|
[i.Parameter] = res.identifier,
|
||||||
type_identifier = res.type_identifier,
|
[i.Tparam] = res.tparam,
|
||||||
tparam = res.tparam,
|
[i.Return] = has_return_statement(),
|
||||||
return_statement = has_return_statement(),
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -168,27 +169,7 @@ local c_config = {
|
|||||||
granulator = nil,
|
granulator = nil,
|
||||||
generator = nil,
|
generator = nil,
|
||||||
|
|
||||||
template = {
|
template = template:add_default_template("doxygen"),
|
||||||
annotation_convention = "doxygen",
|
|
||||||
use_default_comment = false,
|
|
||||||
|
|
||||||
doxygen = {
|
|
||||||
{ nil, "/**", { no_results = true, type = { "func", "file" } } },
|
|
||||||
{ nil, " * @file", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, " * @brief $1", { no_results = true, type = { "func", "file" } } },
|
|
||||||
{ nil, " */", { no_results = true, type = { "func", "file" } } },
|
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ nil, "/**", { type = { "func" } } },
|
|
||||||
{ nil, " * @brief $1", { type = { "func" } } },
|
|
||||||
{ nil, " *", { type = { "func" } } },
|
|
||||||
{ "tparam", " * @tparam %s $1" },
|
|
||||||
{ "parameters", " * @param %s $1" },
|
|
||||||
{ "return_statement", " * @return $1" },
|
|
||||||
{ nil, " */" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return c_config
|
return c_config
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
local c_config = require("neogen.configurations.c")
|
local c_config = require("neogen.configurations.c")
|
||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
local cpp_config = {
|
local cpp_config = {
|
||||||
parent = {
|
parent = {
|
||||||
@@ -12,7 +13,7 @@ local cpp_config = {
|
|||||||
["0"] = {
|
["0"] = {
|
||||||
extract = function(node)
|
extract = function(node)
|
||||||
local tree = {
|
local tree = {
|
||||||
{ retrieve = "first", node_type = "type_identifier", extract = true },
|
{ retrieve = "first", node_type = "type_identifier", extract = true, as = i.ClassName },
|
||||||
}
|
}
|
||||||
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
||||||
local res = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
@@ -22,25 +23,6 @@ local cpp_config = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
template = {
|
|
||||||
|
|
||||||
doxygen = {
|
|
||||||
{ nil, "/**", { no_results = true, type = { "func", "file", "class" } } },
|
|
||||||
{ nil, " * @file", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, " * @brief $1", { no_results = true, type = { "func", "file", "class" } } },
|
|
||||||
{ nil, " */", { no_results = true, type = { "func", "file", "class" } } },
|
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ nil, "/**", { type = { "func", "class" } } },
|
|
||||||
{ "type_identifier", " * @class %s", { type = { "class" } } },
|
|
||||||
{ nil, " * @brief $1", { type = { "func", "class" } } },
|
|
||||||
{ nil, " *", { type = { "func", "class" } } },
|
|
||||||
{ "tparam", " * @tparam %s $1" },
|
|
||||||
{ "parameters", " * @param %s $1" },
|
|
||||||
{ "return_statement", " * @return $1" },
|
|
||||||
{ nil, " */", { type = { "func", "class" } } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cpp_config = vim.tbl_deep_extend("force", c_config, cpp_config)
|
cpp_config = vim.tbl_deep_extend("force", c_config, cpp_config)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
return {
|
return {
|
||||||
parent = {
|
parent = {
|
||||||
@@ -82,7 +84,12 @@ return {
|
|||||||
retrieve = "all",
|
retrieve = "all",
|
||||||
node_type = "parameter",
|
node_type = "parameter",
|
||||||
subtree = {
|
subtree = {
|
||||||
{ retrieve = "first", node_type = "identifier", extract = true },
|
{
|
||||||
|
retrieve = "first",
|
||||||
|
node_type = "identifier",
|
||||||
|
extract = true,
|
||||||
|
as = i.Parameter,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -94,6 +101,7 @@ return {
|
|||||||
{
|
{
|
||||||
retrieve = "all",
|
retrieve = "all",
|
||||||
node_type = "return_statement",
|
node_type = "return_statement",
|
||||||
|
as = i.Return,
|
||||||
recursive = true,
|
recursive = true,
|
||||||
extract = true,
|
extract = true,
|
||||||
},
|
},
|
||||||
@@ -108,33 +116,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
template = {
|
template = template:add_default_template("doxygen"):add_template("xmldoc"),
|
||||||
use_default_comment = false,
|
|
||||||
annotation_convention = "xmldoc",
|
|
||||||
|
|
||||||
xmldoc = {
|
|
||||||
{ nil, "/// <summary>", { no_results = true } },
|
|
||||||
{ nil, "/// $1", { no_results = true } },
|
|
||||||
{ nil, "/// </summary>", { no_results = true } },
|
|
||||||
|
|
||||||
{ nil, "/// <summary>", {} },
|
|
||||||
{ nil, "/// $1", {} },
|
|
||||||
{ "identifier", '/// <param name="%s">$1</param>', { type = { "func", "type" } } },
|
|
||||||
{ "return_statement", "/// <returns>$1</returns>", { type = { "func", "type" } } },
|
|
||||||
{ nil, "/// </summary>", {} },
|
|
||||||
},
|
|
||||||
|
|
||||||
doxygen = {
|
|
||||||
{ nil, "/**", { no_results = true, type = { "func", "class" } } },
|
|
||||||
{ nil, " * @brief $1", { no_results = true, type = { "func", "class" } } },
|
|
||||||
{ nil, " */", { no_results = true, type = { "func", "class" } } },
|
|
||||||
|
|
||||||
{ nil, "/**" },
|
|
||||||
{ nil, " * @brief $1" },
|
|
||||||
{ nil, " *" },
|
|
||||||
{ "identifier", " * @param %s $1" },
|
|
||||||
{ "return_statement", " * @return $1" },
|
|
||||||
{ nil, " */" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
parent = {
|
parent = {
|
||||||
func = { "function_declaration" },
|
func = { "function_declaration" },
|
||||||
@@ -25,10 +27,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
template = {
|
template = template:config({ use_default_comment = true }):add_default_template("godoc"),
|
||||||
annotation_convention = "godoc",
|
|
||||||
godoc = {
|
|
||||||
{ nil, " $1", { no_results = true } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
|
||||||
local function_tree = {
|
local function_tree = {
|
||||||
{
|
{
|
||||||
@@ -112,22 +113,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
template = {
|
template = template:add_default_template("javadoc"),
|
||||||
annotation_convention = "javadoc",
|
|
||||||
use_default_comment = false,
|
|
||||||
|
|
||||||
javadoc = {
|
|
||||||
{ nil, "/**", { no_results = true, type = { "class", "func" } } },
|
|
||||||
{ nil, " * $1", { no_results = true, type = { "class", "func" } } },
|
|
||||||
{ nil, " */", { no_results = true, type = { "class", "func" } } },
|
|
||||||
|
|
||||||
{ nil, "/**" },
|
|
||||||
{ nil, " * $1" },
|
|
||||||
{ nil, " *" },
|
|
||||||
{ "parameters", " * @param %s $1" },
|
|
||||||
{ "return_statement", " * @return $1" },
|
|
||||||
{ "throw_statement", " * @throws $1" },
|
|
||||||
{ nil, " */" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
|
||||||
local function_tree = {
|
local function_tree = {
|
||||||
{
|
{
|
||||||
@@ -84,7 +86,7 @@ return {
|
|||||||
|
|
||||||
extract = function(_)
|
extract = function(_)
|
||||||
local results = {}
|
local results = {}
|
||||||
results.class_tag = { "" }
|
results[i.ClassName] = { "" }
|
||||||
return results
|
return results
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
@@ -110,23 +112,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
template = {
|
template = template:add_default_template("jsdoc"),
|
||||||
annotation_convention = "jsdoc",
|
|
||||||
use_default_comment = false,
|
|
||||||
|
|
||||||
jsdoc = {
|
|
||||||
{ nil, "/* $1 */", { no_results = true, type = { "func", "class" } } },
|
|
||||||
{ nil, "/* @type $1 */", { no_results = true, type = { "type" } } },
|
|
||||||
|
|
||||||
{ nil, "/**", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, " * @module $1", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, " */", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ nil, "/**", { type = { "class", "func" } } },
|
|
||||||
{ "class_tag", " * @classdesc $1", { before_first_item = { " * ", " * @class" }, type = { "class" } } },
|
|
||||||
{ "parameters", " * @param {any} %s $1", { type = { "func" } } },
|
|
||||||
{ "return_statement", " * @returns {$1|any}", { type = { "func" } } },
|
|
||||||
{ nil, " */", { type = { "class", "func" } } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
|
local i = require("neogen.types.template").item
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
|
||||||
local function_extractor = function(node, type)
|
local function_extractor = function(node, type)
|
||||||
if not vim.tbl_contains({ "local", "function" }, type) then
|
if not vim.tbl_contains({ "local", "function" }, type) then
|
||||||
@@ -11,17 +13,17 @@ local function_extractor = function(node, type)
|
|||||||
retrieve = "first",
|
retrieve = "first",
|
||||||
node_type = "parameters",
|
node_type = "parameters",
|
||||||
subtree = {
|
subtree = {
|
||||||
{ retrieve = "all", node_type = "identifier", extract = true },
|
{ retrieve = "all", node_type = "identifier", extract = true, as = i.Parameter },
|
||||||
{ retrieve = "all", node_type = "spread", extract = true },
|
{ retrieve = "all", node_type = "vararg_expression", extract = true, as = i.Vararg },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
retrieve = "first",
|
retrieve = "first",
|
||||||
node_type = "block",
|
node_type = "block",
|
||||||
subtree = {
|
subtree = {
|
||||||
{ retrieve = "first", node_type = "return_statement", extract = true },
|
{ retrieve = "first", node_type = "return_statement", extract = true, as = i.Return },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if type == "local" then
|
if type == "local" then
|
||||||
@@ -37,12 +39,7 @@ local function_extractor = function(node, type)
|
|||||||
|
|
||||||
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
||||||
local res = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
|
return res
|
||||||
return {
|
|
||||||
parameters = res.identifier,
|
|
||||||
vararg = res.spread,
|
|
||||||
return_statement = res.return_statement,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local extract_from_var = function(node)
|
local extract_from_var = function(node)
|
||||||
@@ -104,7 +101,7 @@ return {
|
|||||||
local nodes = extract_from_var(node)
|
local nodes = extract_from_var(node)
|
||||||
local res = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
return {
|
return {
|
||||||
class_name = res.identifier,
|
[i.ClassName] = res.identifier,
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
@@ -115,7 +112,7 @@ return {
|
|||||||
["0"] = {
|
["0"] = {
|
||||||
extract = function(node)
|
extract = function(node)
|
||||||
local result = {}
|
local result = {}
|
||||||
result.type = {}
|
result[i.Type] = {}
|
||||||
|
|
||||||
local nodes = extract_from_var(node)
|
local nodes = extract_from_var(node)
|
||||||
local res = extractors:extract_from_matched(nodes, { type = true })
|
local res = extractors:extract_from_matched(nodes, { type = true })
|
||||||
@@ -123,10 +120,10 @@ return {
|
|||||||
-- We asked the extract_from_var function to find the type node at right assignment.
|
-- We asked the extract_from_var function to find the type node at right assignment.
|
||||||
-- We check if it found it, or else will put `any` in the type
|
-- We check if it found it, or else will put `any` in the type
|
||||||
if res["_"] then
|
if res["_"] then
|
||||||
vim.list_extend(result.type, res["_"])
|
vim.list_extend(result[i.Type], res["_"])
|
||||||
else
|
else
|
||||||
if res.identifier or res.field_expression then
|
if res.identifier or res.field_expression then
|
||||||
vim.list_extend(result.type, { "any" })
|
vim.list_extend(result[i.Type], { "any" })
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
@@ -152,29 +149,5 @@ return {
|
|||||||
granulator = nil,
|
granulator = nil,
|
||||||
generator = nil,
|
generator = nil,
|
||||||
|
|
||||||
template = {
|
template = template:config({ use_default_comment = true }):add_default_template("emmylua"):add_template("ldoc"),
|
||||||
-- Which annotation convention to use
|
|
||||||
annotation_convention = "emmylua",
|
|
||||||
emmylua = {
|
|
||||||
{ nil, "-$1", { type = { "class", "func" } } }, -- add this string only on requested types
|
|
||||||
{ nil, "-$1", { no_results = true, type = { "class", "func" } } }, -- Shows only when there's no results from the granulator
|
|
||||||
{ nil, "-@module $1", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "-@author $1", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "-@license $1", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ "parameters", "-@param %s $1|any" },
|
|
||||||
{ "vararg", "-@vararg $1|any" },
|
|
||||||
{ "return_statement", "-@return $1|any" },
|
|
||||||
{ "class_name", "-@class $1|any" },
|
|
||||||
{ "type", "-@type $1" },
|
|
||||||
},
|
|
||||||
ldoc = {
|
|
||||||
{ nil, "- $1", { no_results = true, type = { "func", "class" } } },
|
|
||||||
{ nil, "- $1", { type = { "func", "class" } } },
|
|
||||||
|
|
||||||
{ "parameters", " @tparam $1|any %s " },
|
|
||||||
{ "return_statement", " @treturn $1|any" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
return {
|
return {
|
||||||
parent = {
|
parent = {
|
||||||
@@ -13,7 +15,7 @@ return {
|
|||||||
["0"] = {
|
["0"] = {
|
||||||
extract = function(node)
|
extract = function(node)
|
||||||
local tree = {
|
local tree = {
|
||||||
{ node_type = "property_element", retrieve = "all", extract = true },
|
{ node_type = "property_element", retrieve = "all", extract = true, as = i.Type },
|
||||||
}
|
}
|
||||||
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
||||||
local res = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
@@ -39,6 +41,7 @@ return {
|
|||||||
node_type = "variable_name",
|
node_type = "variable_name",
|
||||||
retrieve = "all",
|
retrieve = "all",
|
||||||
extract = true,
|
extract = true,
|
||||||
|
as = i.Parameter,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -53,6 +56,7 @@ return {
|
|||||||
node_type = "return_statement",
|
node_type = "return_statement",
|
||||||
recursive = true,
|
recursive = true,
|
||||||
extract = true,
|
extract = true,
|
||||||
|
as = i.Return,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -74,24 +78,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
template = {
|
template = template:add_default_template("phpdoc"),
|
||||||
annotation_convention = "phpdoc",
|
|
||||||
use_default_comment = false,
|
|
||||||
|
|
||||||
phpdoc = {
|
|
||||||
{ nil, "/** @var $1 */", { no_results = true, type = { "type" } } },
|
|
||||||
|
|
||||||
{ nil, "/**", { no_results = true, type = { "func", "class" } } },
|
|
||||||
{ nil, " * $1", { no_results = true, type = { "func", "class" } } },
|
|
||||||
{ nil, " */", { no_results = true, type = { "func", "class" } } },
|
|
||||||
|
|
||||||
{ 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" } } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ local ts_utils = require("nvim-treesitter.ts_utils")
|
|||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
local locator = require("neogen.locators.default")
|
local locator = require("neogen.locators.default")
|
||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
local parent = {
|
local parent = {
|
||||||
func = { "function_definition" },
|
func = { "function_definition" },
|
||||||
@@ -75,7 +77,7 @@ return {
|
|||||||
{
|
{
|
||||||
retrieve = "all",
|
retrieve = "all",
|
||||||
node_type = "type",
|
node_type = "type",
|
||||||
as = "return_type",
|
as = i.ReturnTypeHint,
|
||||||
extract = true,
|
extract = true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -84,8 +86,8 @@ return {
|
|||||||
results["typed_parameters"] = {}
|
results["typed_parameters"] = {}
|
||||||
for _, n in pairs(nodes["typed_parameter"]) do
|
for _, n in pairs(nodes["typed_parameter"]) do
|
||||||
local type_subtree = {
|
local type_subtree = {
|
||||||
{ retrieve = "all", node_type = "identifier", extract = true },
|
{ retrieve = "all", node_type = "identifier", extract = true, as = i.Parameter },
|
||||||
{ retrieve = "all", node_type = "type", extract = true },
|
{ retrieve = "all", node_type = "type", extract = true, as = i.Type },
|
||||||
}
|
}
|
||||||
local typed_parameters = nodes_utils:matching_nodes_from(n, type_subtree)
|
local typed_parameters = nodes_utils:matching_nodes_from(n, type_subtree)
|
||||||
typed_parameters = extractors:extract_from_matched(typed_parameters)
|
typed_parameters = extractors:extract_from_matched(typed_parameters)
|
||||||
@@ -100,11 +102,11 @@ return {
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Return type hints takes precedence over all other types for generating template
|
-- Return type hints takes precedence over all other types for generating template
|
||||||
if res["return_type"] then
|
if res[i.ReturnTypeHint] then
|
||||||
res["return_statement"] = nil
|
res["return_statement"] = nil
|
||||||
res["anonymous_return"] = nil
|
res["anonymous_return"] = nil
|
||||||
if res["return_type"][1] == "None" then
|
if res[i.ReturnTypeHint][1] == "None" then
|
||||||
res["return_type"] = nil
|
res[i.ReturnTypeHint] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -128,13 +130,13 @@ return {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
results.has_identifier = (res.typed_parameter or res.identifier) and { true } or nil
|
results[i.HasParameter] = (res.typed_parameter or res.identifier) and { true } or nil
|
||||||
results.type = res.type
|
results[i.Type] = res.type
|
||||||
results.parameters = res.identifier
|
results[i.Parameter] = res.identifier
|
||||||
results.anonymous_return = res.anonymous_return
|
results[i.ReturnAnonym] = res.anonymous_return
|
||||||
results.return_statement = res.return_statement
|
results[i.Return] = res.return_statement
|
||||||
results.return_type = res.return_type
|
results[i.ReturnTypeHint] = res[i.ReturnTypeHint]
|
||||||
results.has_return = (res.return_statement or res.anonymous_return or res.return_type)
|
results[i.HasReturn] = (res.return_statement or res.anonymous_return or res[i.ReturnTypeHint])
|
||||||
and { true }
|
and { true }
|
||||||
or nil
|
or nil
|
||||||
return results
|
return results
|
||||||
@@ -185,17 +187,17 @@ return {
|
|||||||
return {}
|
return {}
|
||||||
end
|
end
|
||||||
|
|
||||||
results.attributes = {}
|
results[i.ClassAttribute] = {}
|
||||||
for _, assignment in pairs(nodes["assignment"]) do
|
for _, assignment in pairs(nodes["assignment"]) do
|
||||||
local left_side = assignment:field("left")[1]
|
local left_side = assignment:field("left")[1]
|
||||||
local left_attribute = left_side:field("attribute")[1]
|
local left_attribute = left_side:field("attribute")[1]
|
||||||
left_attribute = ts_utils.get_node_text(left_attribute)[1]
|
left_attribute = ts_utils.get_node_text(left_attribute)[1]
|
||||||
if left_attribute and not vim.startswith(left_attribute, "_") then
|
if left_attribute and not vim.startswith(left_attribute, "_") then
|
||||||
table.insert(results.attributes, left_attribute)
|
table.insert(results[i.ClassAttribute], left_attribute)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if vim.tbl_isempty(results.attributes) then
|
if vim.tbl_isempty(results[i.ClassAttribute]) then
|
||||||
results.attributes = nil
|
results[i.ClassAttribute] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
return results
|
return results
|
||||||
@@ -226,10 +228,9 @@ return {
|
|||||||
granulator = nil,
|
granulator = nil,
|
||||||
generator = nil,
|
generator = nil,
|
||||||
|
|
||||||
template = {
|
template = template
|
||||||
annotation_convention = "google_docstrings", -- required: Which annotation convention to use (default_generator)
|
:config({
|
||||||
append = { position = "after", child_name = "comment", fallback = "block" }, -- optional: where to append the text (default_generator)
|
append = { position = "after", child_name = "comment", fallback = "block" }, -- optional: where to append the text (default_generator)
|
||||||
use_default_comment = false, -- If you want to prefix the template with the default comment for the language, e.g for python: # (default_generator)
|
|
||||||
position = function(node, type)
|
position = function(node, type)
|
||||||
if type == "file" then
|
if type == "file" then
|
||||||
-- Checks if the file starts with #!, that means it's a shebang line
|
-- Checks if the file starts with #!, that means it's a shebang line
|
||||||
@@ -247,103 +248,8 @@ return {
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
})
|
||||||
google_docstrings = {
|
:add_default_template("google_docstrings")
|
||||||
{ nil, '""" $1 """', { no_results = true, type = { "class", "func" } } },
|
:add_template("numpydoc")
|
||||||
{ nil, '"""$1', { no_results = true, type = { "file" } } },
|
:add_template("reST"),
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "$1", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, '"""', { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ nil, "# $1", { no_results = true, type = { "type" } } },
|
|
||||||
|
|
||||||
{ nil, '"""$1' },
|
|
||||||
{ "has_identifier", "", { type = { "func" } } },
|
|
||||||
{ "has_identifier", "Args:", { type = { "func" } } },
|
|
||||||
{ "parameters", " %s ($1): $1", { type = { "func" } } },
|
|
||||||
{ { "identifier", "type" }, " %s (%s): $1", { required = "typed_parameters", type = { "func" } } },
|
|
||||||
{ "attributes", " %s: $1", { before_first_item = { "", "Attributes: " } } },
|
|
||||||
{ "has_return", "", { type = { "func" } } },
|
|
||||||
{ "has_return", "Returns:", { type = { "func" } } },
|
|
||||||
{ "has_return", " $1", { type = { "func" } } },
|
|
||||||
{ nil, '"""' },
|
|
||||||
},
|
|
||||||
numpydoc = {
|
|
||||||
{ nil, '""" $1 """', { no_results = true, type = { "class", "func" } } },
|
|
||||||
{ nil, '"""$1', { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "$1", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, '"""', { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ nil, "# $1", { no_results = true, type = { "type" } } },
|
|
||||||
|
|
||||||
{ nil, '"""$1' },
|
|
||||||
{ "has_identifier", "", { type = { "func" } } },
|
|
||||||
{ "has_identifier", "Parameters", { type = { "func" } } },
|
|
||||||
{ "has_identifier", "----------", { type = { "func" } } },
|
|
||||||
{
|
|
||||||
"parameters",
|
|
||||||
"%s : $1",
|
|
||||||
{ after_each = " $1", type = { "func" } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{ "identifier", "type" },
|
|
||||||
"%s : %s",
|
|
||||||
{ after_each = " $1", required = "typed_parameters", type = { "func" } },
|
|
||||||
},
|
|
||||||
{ "attributes", "%s : $1", { before_first_item = { "", "Attributes", "----------" } } },
|
|
||||||
{ "has_return", "", { type = { "func" } } },
|
|
||||||
{ "has_return", "Returns", { type = { "func" } } },
|
|
||||||
{ "has_return", "-------", { type = { "func" } } },
|
|
||||||
{
|
|
||||||
"return_type",
|
|
||||||
"%s",
|
|
||||||
{ after_each = " $1" },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"return_statement",
|
|
||||||
"%s : $1",
|
|
||||||
{ after_each = " $1" },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"anonymous_return",
|
|
||||||
"%s",
|
|
||||||
{ after_each = " $1" },
|
|
||||||
},
|
|
||||||
{ nil, '"""' },
|
|
||||||
},
|
|
||||||
reST = {
|
|
||||||
{ nil, '""" $1 """', { no_results = true, type = { "class", "func" } } },
|
|
||||||
{ nil, '"""$1', { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "$1", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, '"""', { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ nil, "# $1", { no_results = true, type = { "type" } } },
|
|
||||||
|
|
||||||
{ nil, '"""$1' },
|
|
||||||
{ nil, "" },
|
|
||||||
{
|
|
||||||
"parameters",
|
|
||||||
":param %s: $1",
|
|
||||||
{ after_each = ":type %s: $1", type = { "func" } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{ "identifier", "type" },
|
|
||||||
":param %s: $1",
|
|
||||||
{
|
|
||||||
after_each = ":type %s: %s $1",
|
|
||||||
required = "typed_parameters",
|
|
||||||
type = { "func" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{ "attributes", ":param %s: $1" },
|
|
||||||
{ "has_return", ":return: $1", { type = { "func" } } },
|
|
||||||
{ "has_return", ":rtype: $1", { type = { "func" } } },
|
|
||||||
{ nil, '"""' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
|
local i = require("neogen.types.template").item
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
|
||||||
return {
|
return {
|
||||||
parent = {
|
parent = {
|
||||||
@@ -21,13 +23,19 @@ return {
|
|||||||
retrieve = "all",
|
retrieve = "all",
|
||||||
node_type = "parameter",
|
node_type = "parameter",
|
||||||
subtree = {
|
subtree = {
|
||||||
{ retrieve = "first", node_type = "identifier", extract = true },
|
{
|
||||||
|
retrieve = "first",
|
||||||
|
node_type = "identifier",
|
||||||
|
extract = true,
|
||||||
|
i.Parameter,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
retrieve = "all",
|
retrieve = "all",
|
||||||
node_type = "type_identifier",
|
node_type = "type_identifier",
|
||||||
extract = true,
|
extract = true,
|
||||||
|
as = i.Tparam,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -61,7 +69,12 @@ return {
|
|||||||
retrieve = "all",
|
retrieve = "all",
|
||||||
node_type = "field_declaration",
|
node_type = "field_declaration",
|
||||||
subtree = {
|
subtree = {
|
||||||
{ retrieve = "all", node_type = "field_identifier", extract = true },
|
{
|
||||||
|
retrieve = "all",
|
||||||
|
node_type = "field_identifier",
|
||||||
|
extract = true,
|
||||||
|
as = i.Parameter,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -76,27 +89,8 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
template = {
|
template = template
|
||||||
annotation_convention = "alternative",
|
:config({ use_default_comment = true })
|
||||||
rustdoc = {
|
:add_template("rustdoc")
|
||||||
{ nil, "! $1", { no_results = true, type = { "file" } } },
|
:add_default_template("rust_alternative"),
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ nil, "/ $1", { no_results = true, type = { "func", "class" } } },
|
|
||||||
{ nil, "/ $1", { type = { "func", "class" } } },
|
|
||||||
},
|
|
||||||
|
|
||||||
alternative = {
|
|
||||||
{ nil, "! $1", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, "", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ nil, "/ $1", { no_results = true, type = { "func", "class" } } },
|
|
||||||
|
|
||||||
{ nil, "/ $1", { type = { "func", "class" } } },
|
|
||||||
{ nil, "/", { type = { "class", "func" } } },
|
|
||||||
{ "field_identifier", "/ * `%s`: $1", { type = { "class" } } },
|
|
||||||
{ "type_identifier", "/ * `%s`: $1", { type = { "func" } } },
|
|
||||||
{ "identifier", "/ * `%s`: $1", { type = { "func" } } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
local extractors = require("neogen.utilities.extractors")
|
local extractors = require("neogen.utilities.extractors")
|
||||||
local nodes_utils = require("neogen.utilities.nodes")
|
local nodes_utils = require("neogen.utilities.nodes")
|
||||||
|
local i = require("neogen.types.template").item
|
||||||
|
local template = require("neogen.utilities.template")
|
||||||
|
|
||||||
local construct_type_annotation = function(parameters)
|
local construct_type_annotation = function(parameters)
|
||||||
local results = parameters and {} or nil
|
local results = parameters and {} or nil
|
||||||
if parameters then
|
if parameters then
|
||||||
for _, param in pairs(parameters) do
|
for _, param in pairs(parameters) do
|
||||||
local subtree = {
|
local subtree = {
|
||||||
{ retrieve = "all", node_type = "identifier", extract = true },
|
{ retrieve = "all", node_type = "identifier", extract = true, as = i.Parameter },
|
||||||
{ retrieve = "all", node_type = "type_identifier", recursive = true, extract = true },
|
{ retrieve = "all", node_type = "type_identifier", recursive = true, extract = true, as = i.Type },
|
||||||
}
|
}
|
||||||
local typed_parameters = nodes_utils:matching_nodes_from(param, subtree)
|
local typed_parameters = nodes_utils:matching_nodes_from(param, subtree)
|
||||||
typed_parameters = extractors:extract_from_matched(typed_parameters)
|
typed_parameters = extractors:extract_from_matched(typed_parameters)
|
||||||
@@ -26,11 +28,13 @@ local function_tree = {
|
|||||||
retrieve = "all",
|
retrieve = "all",
|
||||||
node_type = "required_parameter",
|
node_type = "required_parameter",
|
||||||
extract = true,
|
extract = true,
|
||||||
|
as = i.Tparam,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
retrieve = "all",
|
retrieve = "all",
|
||||||
node_type = "optional_parameter",
|
node_type = "optional_parameter",
|
||||||
extract = true,
|
extract = true,
|
||||||
|
as = i.Tparam,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -38,7 +42,7 @@ local function_tree = {
|
|||||||
retrieve = "first",
|
retrieve = "first",
|
||||||
node_type = "statement_block",
|
node_type = "statement_block",
|
||||||
subtree = {
|
subtree = {
|
||||||
{ retrieve = "first", node_type = "return_statement", extract = true },
|
{ retrieve = "first", node_type = "return_statement", extract = true, as = i.Return },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -57,48 +61,33 @@ return {
|
|||||||
["0"] = {
|
["0"] = {
|
||||||
|
|
||||||
extract = function(node)
|
extract = function(node)
|
||||||
local results = {}
|
|
||||||
local tree = function_tree
|
local tree = function_tree
|
||||||
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
||||||
local res = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
|
res[i.Tparam] = construct_type_annotation(nodes[i.Tparam])
|
||||||
results.type = construct_type_annotation(nodes.required_parameter)
|
return res
|
||||||
results.opt_type = construct_type_annotation(nodes.optional_parameter)
|
|
||||||
results.parameters = res.identifier
|
|
||||||
results.return_statement = res.return_statement
|
|
||||||
return results
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
["expression_statement|variable_declaration"] = {
|
["expression_statement|variable_declaration"] = {
|
||||||
["0"] = {
|
["0"] = {
|
||||||
extract = function(node)
|
extract = function(node)
|
||||||
local results = {}
|
|
||||||
local tree = { { retrieve = "all", node_type = "function", subtree = function_tree } }
|
local tree = { { retrieve = "all", node_type = "function", subtree = function_tree } }
|
||||||
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
||||||
local res = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
|
res[i.Tparam] = construct_type_annotation(nodes[i.Tparam])
|
||||||
results.type = construct_type_annotation(nodes.type_annotation)
|
return res
|
||||||
results.opt_type = construct_type_annotation(nodes.optional_parameter)
|
|
||||||
results.parameters = res.identifier
|
|
||||||
results.return_statement = res.return_statement
|
|
||||||
return results
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
["lexical_declaration"] = {
|
["lexical_declaration"] = {
|
||||||
["1"] = {
|
["1"] = {
|
||||||
extract = function(node)
|
extract = function(node)
|
||||||
local results = {}
|
|
||||||
local tree = { { retrieve = "all", node_type = "arrow_function", subtree = function_tree } }
|
local tree = { { retrieve = "all", node_type = "arrow_function", subtree = function_tree } }
|
||||||
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
||||||
local res = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
|
res[i.Tparam] = construct_type_annotation(nodes[i.Tparam])
|
||||||
results.type = construct_type_annotation(nodes.type_annotation)
|
return res
|
||||||
results.opt_type = construct_type_annotation(nodes.optional_parameter)
|
|
||||||
results.parameters = res.identifier
|
|
||||||
results.return_statement = res.return_statement
|
|
||||||
return results
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -109,7 +98,7 @@ return {
|
|||||||
|
|
||||||
extract = function(_)
|
extract = function(_)
|
||||||
local results = {}
|
local results = {}
|
||||||
results.class_tag = { "" }
|
results[i.ClassName] = { "" }
|
||||||
return results
|
return results
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
@@ -119,18 +108,16 @@ return {
|
|||||||
["variable_declaration|lexical_declaration"] = {
|
["variable_declaration|lexical_declaration"] = {
|
||||||
["1"] = {
|
["1"] = {
|
||||||
extract = function(node)
|
extract = function(node)
|
||||||
local res = {}
|
|
||||||
local tree = {
|
local tree = {
|
||||||
{
|
{
|
||||||
retrieve = "first",
|
retrieve = "first",
|
||||||
node_type = "identifier",
|
node_type = "identifier",
|
||||||
extract = true,
|
extract = true,
|
||||||
|
as = i.Type,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
local nodes = nodes_utils:matching_nodes_from(node, tree)
|
||||||
local results = extractors:extract_from_matched(nodes)
|
local res = extractors:extract_from_matched(nodes)
|
||||||
|
|
||||||
res.type = results.identifier
|
|
||||||
return res
|
return res
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
@@ -147,32 +134,5 @@ return {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
template = {
|
template = template:add_default_template("jsdoc"),
|
||||||
annotation_convention = "jsdoc",
|
|
||||||
use_default_comment = false,
|
|
||||||
jsdoc = {
|
|
||||||
{ nil, "/* $1 */", { no_results = true, type = { "class", "func" } } },
|
|
||||||
|
|
||||||
{ nil, "/**", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, " * @module $1", { no_results = true, type = { "file" } } },
|
|
||||||
{ nil, " */", { no_results = true, type = { "file" } } },
|
|
||||||
|
|
||||||
{ nil, "/**", { type = { "class", "func" } } },
|
|
||||||
{ "class_tag", " * @classdesc $1", { before_first_item = { " * ", " * @class" }, type = { "class" } } },
|
|
||||||
{
|
|
||||||
{ "type_identifier", "identifier" },
|
|
||||||
" * @param {%s} %s $1",
|
|
||||||
{ required = "opt_type", type = { "func" } },
|
|
||||||
},
|
|
||||||
{
|
|
||||||
{ "type_identifier", "identifier" },
|
|
||||||
" * @param {%s} %s $1",
|
|
||||||
{ required = "type", type = { "func" } },
|
|
||||||
},
|
|
||||||
{ "return_statement", " * @returns {$1} $1", { type = { "func" } } },
|
|
||||||
{ nil, " */", { type = { "class", "func" } } },
|
|
||||||
|
|
||||||
{ "type", "/* @type {$1|any} */", { type = { "type" } } },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|||||||
17
lua/neogen/templates/doxygen.lua
Normal file
17
lua/neogen/templates/doxygen.lua
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
return {
|
||||||
|
{ nil, "/**", { no_results = true, type = { "func", "file", "class" } } },
|
||||||
|
{ nil, " * @file", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, " * @brief $1", { no_results = true, type = { "func", "file", "class" } } },
|
||||||
|
{ nil, " */", { no_results = true, type = { "func", "file", "class" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
|
{ nil, "/**", { type = { "func", "class" } } },
|
||||||
|
{ i.ClassName, " * @class %s", { type = { "class" } } },
|
||||||
|
{ nil, " * @brief $1", { type = { "func", "class" } } },
|
||||||
|
{ nil, " *", { type = { "func", "class" } } },
|
||||||
|
{ i.Tparam, " * @tparam %s $1" },
|
||||||
|
{ i.Parameter, " * @param %s $1" },
|
||||||
|
{ i.Return, " * @return $1" },
|
||||||
|
{ nil, " */", { type = { "func", "class" } } },
|
||||||
|
}
|
||||||
16
lua/neogen/templates/emmylua.lua
Normal file
16
lua/neogen/templates/emmylua.lua
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, "-$1", { type = { "class", "func" } } }, -- add this string only on requested types
|
||||||
|
{ nil, "-$1", { no_results = true, type = { "class", "func" } } }, -- Shows only when there's no results from the granulator
|
||||||
|
{ nil, "-@module $1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "-@author $1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "-@license $1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
|
{ i.Parameter, "-@param %s $1|any" },
|
||||||
|
{ i.Vararg, "-@vararg $1|any" },
|
||||||
|
{ i.Return, "-@return $1|any" },
|
||||||
|
{ i.ClassName, "-@class $1|any" },
|
||||||
|
{ i.Type, "-@type $1" },
|
||||||
|
}
|
||||||
3
lua/neogen/templates/godoc.lua
Normal file
3
lua/neogen/templates/godoc.lua
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
return {
|
||||||
|
{ nil, " $1", { no_results = true } },
|
||||||
|
}
|
||||||
23
lua/neogen/templates/google_docstrings.lua
Normal file
23
lua/neogen/templates/google_docstrings.lua
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, '""" $1 """', { no_results = true, type = { "class", "func" } } },
|
||||||
|
{ nil, '"""$1', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "$1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, '"""', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
|
{ nil, "# $1", { no_results = true, type = { "type" } } },
|
||||||
|
|
||||||
|
{ nil, '"""$1' },
|
||||||
|
{ i.HasParameter, "", { type = { "func" } } },
|
||||||
|
{ i.HasParameter, "Args:", { type = { "func" } } },
|
||||||
|
{ i.Parameter, " %s ($1): $1", { type = { "func" } } },
|
||||||
|
{ { i.Parameter, i.Type }, " %s (%s): $1", { required = "typed_parameters", type = { "func" } } },
|
||||||
|
{ i.ClassAttribute, " %s: $1", { before_first_item = { "", "Attributes: " } } },
|
||||||
|
{ i.HasReturn, "", { type = { "func" } } },
|
||||||
|
{ i.HasReturn, "Returns:", { type = { "func" } } },
|
||||||
|
{ i.HasReturn, " $1", { type = { "func" } } },
|
||||||
|
{ nil, '"""' },
|
||||||
|
}
|
||||||
15
lua/neogen/templates/javadoc.lua
Normal file
15
lua/neogen/templates/javadoc.lua
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, "/**", { no_results = true, type = { "class", "func" } } },
|
||||||
|
{ nil, " * $1", { no_results = true, type = { "class", "func" } } },
|
||||||
|
{ nil, " */", { no_results = true, type = { "class", "func" } } },
|
||||||
|
|
||||||
|
{ nil, "/**" },
|
||||||
|
{ nil, " * $1" },
|
||||||
|
{ nil, " *" },
|
||||||
|
{ i.Parameter, " * @param %s $1" },
|
||||||
|
{ i.Return, " * @return $1" },
|
||||||
|
{ i.Throw, " * @throws $1" },
|
||||||
|
{ nil, " */" },
|
||||||
|
}
|
||||||
21
lua/neogen/templates/jsdoc.lua
Normal file
21
lua/neogen/templates/jsdoc.lua
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, "/* $1 */", { no_results = true, type = { "func", "class" } } },
|
||||||
|
{ nil, "/* @type $1 */", { no_results = true, type = { "type" } } },
|
||||||
|
|
||||||
|
{ nil, "/**", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, " * @module $1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, " */", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
|
{ nil, "/**", { type = { "class", "func" } } },
|
||||||
|
{ i.ClassName, " * @classdesc $1", { before_first_item = { " * ", " * @class" }, type = { "class" } } },
|
||||||
|
{ i.Parameter, " * @param {any} %s $1", { type = { "func" } } },
|
||||||
|
{
|
||||||
|
{ i.Type, i.Parameter },
|
||||||
|
" * @param {%s} %s $1",
|
||||||
|
{ required = i.Tparam, type = { "func" } },
|
||||||
|
},
|
||||||
|
{ i.Return, " * @returns {$1} $1", { type = { "func" } } },
|
||||||
|
{ nil, " */", { type = { "class", "func" } } },
|
||||||
|
}
|
||||||
9
lua/neogen/templates/ldoc.lua
Normal file
9
lua/neogen/templates/ldoc.lua
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, "- $1", { no_results = true, type = { "func", "class" } } },
|
||||||
|
{ nil, "- $1", { type = { "func", "class" } } },
|
||||||
|
|
||||||
|
{ i.Parameter, " @tparam $1|any %s " },
|
||||||
|
{ i.Return, " @treturn $1|any" },
|
||||||
|
}
|
||||||
47
lua/neogen/templates/numpydoc.lua
Normal file
47
lua/neogen/templates/numpydoc.lua
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, '""" $1 """', { no_results = true, type = { "class", "func" } } },
|
||||||
|
{ nil, '"""$1', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "$1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, '"""', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
|
{ nil, "# $1", { no_results = true, type = { "type" } } },
|
||||||
|
|
||||||
|
{ nil, '"""$1' },
|
||||||
|
{ i.HasParameter, "", { type = { "func" } } },
|
||||||
|
{ i.HasParameter, "Parameters", { type = { "func" } } },
|
||||||
|
{ i.HasParameter, "----------", { type = { "func" } } },
|
||||||
|
{
|
||||||
|
i.Parameter,
|
||||||
|
"%s : $1",
|
||||||
|
{ after_each = " $1", type = { "func" } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ i.Parameter, i.Type },
|
||||||
|
"%s : %s",
|
||||||
|
{ after_each = " $1", required = "typed_parameters", type = { "func" } },
|
||||||
|
},
|
||||||
|
{ i.ClassAttribute, "%s : $1", { before_first_item = { "", "Attributes", "----------" } } },
|
||||||
|
{ i.HasReturn, "", { type = { "func" } } },
|
||||||
|
{ i.HasReturn, "Returns", { type = { "func" } } },
|
||||||
|
{ i.HasReturn, "-------", { type = { "func" } } },
|
||||||
|
{
|
||||||
|
i.ReturnTypeHint,
|
||||||
|
"%s",
|
||||||
|
{ after_each = " $1" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
i.Return,
|
||||||
|
"%s : $1",
|
||||||
|
{ after_each = " $1" },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
i.ReturnAnonym,
|
||||||
|
"%s",
|
||||||
|
{ after_each = " $1" },
|
||||||
|
},
|
||||||
|
{ nil, '"""' },
|
||||||
|
}
|
||||||
17
lua/neogen/templates/phpdoc.lua
Normal file
17
lua/neogen/templates/phpdoc.lua
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, "/** @var $1 */", { no_results = true, type = { "type" } } },
|
||||||
|
|
||||||
|
{ nil, "/**", { no_results = true, type = { "func", "class" } } },
|
||||||
|
{ nil, " * $1", { no_results = true, type = { "func", "class" } } },
|
||||||
|
{ nil, " */", { no_results = true, type = { "func", "class" } } },
|
||||||
|
|
||||||
|
{ nil, "/**", { type = { "type", "func" } } },
|
||||||
|
{ nil, " * $1", { type = { "func" } } },
|
||||||
|
{ nil, " *", { type = { "func" } } },
|
||||||
|
{ i.Type, " * @var $1", { type = { "type" } } },
|
||||||
|
{ i.Parameter, " * @param $1 %s $1", { type = { "func" } } },
|
||||||
|
{ i.Return, " * @return $1", { type = { "func" } } },
|
||||||
|
{ nil, " */", { type = { "type", "func" } } },
|
||||||
|
}
|
||||||
33
lua/neogen/templates/reST.lua
Normal file
33
lua/neogen/templates/reST.lua
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, '""" $1 """', { no_results = true, type = { "class", "func" } } },
|
||||||
|
{ nil, '"""$1', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "$1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, '"""', { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
|
{ nil, "# $1", { no_results = true, type = { "type" } } },
|
||||||
|
|
||||||
|
{ nil, '"""$1' },
|
||||||
|
{ nil, "" },
|
||||||
|
{
|
||||||
|
i.Parameter,
|
||||||
|
":param %s: $1",
|
||||||
|
{ after_each = ":type %s: $1", type = { "func" } },
|
||||||
|
},
|
||||||
|
{
|
||||||
|
{ i.Parameter, i.Type },
|
||||||
|
":param %s: $1",
|
||||||
|
{
|
||||||
|
after_each = ":type %s: %s $1",
|
||||||
|
required = "typed_parameters",
|
||||||
|
type = { "func" },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{ i.ClassAttribute, ":param %s: $1" },
|
||||||
|
{ i.HasReturn, ":return: $1", { type = { "func" } } },
|
||||||
|
{ i.HasReturn, ":rtype: $1", { type = { "func" } } },
|
||||||
|
{ nil, '"""' },
|
||||||
|
}
|
||||||
14
lua/neogen/templates/rust_alternative.lua
Normal file
14
lua/neogen/templates/rust_alternative.lua
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, "! $1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
|
{ nil, "/ $1", { no_results = true, type = { "func", "class" } } },
|
||||||
|
|
||||||
|
{ nil, "/ $1", { type = { "func", "class" } } },
|
||||||
|
{ nil, "/", { type = { "class", "func" } } },
|
||||||
|
{ i.Parameter, "/ * `%s`: $1", { type = { "class" } } },
|
||||||
|
{ i.Tparam, "/ * `%s`: $1", { type = { "func" } } },
|
||||||
|
{ i.Parameter, "/ * `%s`: $1", { type = { "func" } } },
|
||||||
|
}
|
||||||
7
lua/neogen/templates/rustdoc.lua
Normal file
7
lua/neogen/templates/rustdoc.lua
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
return {
|
||||||
|
{ nil, "! $1", { no_results = true, type = { "file" } } },
|
||||||
|
{ nil, "", { no_results = true, type = { "file" } } },
|
||||||
|
|
||||||
|
{ nil, "/ $1", { no_results = true, type = { "func", "class" } } },
|
||||||
|
{ nil, "/ $1", { type = { "func", "class" } } },
|
||||||
|
}
|
||||||
13
lua/neogen/templates/xmldoc.lua
Normal file
13
lua/neogen/templates/xmldoc.lua
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
local i = require("neogen.types.template").item
|
||||||
|
|
||||||
|
return {
|
||||||
|
{ nil, "/// <summary>", { no_results = true } },
|
||||||
|
{ nil, "/// $1", { no_results = true } },
|
||||||
|
{ nil, "/// </summary>", { no_results = true } },
|
||||||
|
|
||||||
|
{ nil, "/// <summary>", {} },
|
||||||
|
{ nil, "/// $1", {} },
|
||||||
|
{ i.Parameter, '/// <param name="%s">$1</param>', { type = { "func", "type" } } },
|
||||||
|
{ i.Return, "/// <returns>$1</returns>", { type = { "func", "type" } } },
|
||||||
|
{ nil, "/// </summary>", {} },
|
||||||
|
}
|
||||||
28
lua/neogen/types/template.lua
Normal file
28
lua/neogen/types/template.lua
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
---@class neogen.TemplateConfig
|
||||||
|
---@field annotation_convention string
|
||||||
|
---@field use_default_comment boolean
|
||||||
|
---@field append? neogen.TemplateConfig.Append
|
||||||
|
|
||||||
|
---@class neogen.TemplateConfig.Append
|
||||||
|
---@field position "'after'"|"'before'"
|
||||||
|
---@field child_name string
|
||||||
|
---@field fallback string
|
||||||
|
|
||||||
|
local template = {}
|
||||||
|
|
||||||
|
template.item = {
|
||||||
|
Tparam = "tparam",
|
||||||
|
Parameter = "parameters",
|
||||||
|
Return = "return_statement",
|
||||||
|
ReturnTypeHint = "return_type_hint",
|
||||||
|
ReturnAnonym = "return_anonym",
|
||||||
|
ClassName = "class_name",
|
||||||
|
Throw = "throw_statement",
|
||||||
|
Vararg = "varargs",
|
||||||
|
Type = "type",
|
||||||
|
ClassAttribute = "attributes",
|
||||||
|
HasParameter = "has_parameters",
|
||||||
|
HasReturn = "has_return",
|
||||||
|
}
|
||||||
|
|
||||||
|
return template
|
||||||
31
lua/neogen/utilities/template.lua
Normal file
31
lua/neogen/utilities/template.lua
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
---@type neogen.TemplateConfig
|
||||||
|
local template = {
|
||||||
|
annotation_convention = nil,
|
||||||
|
use_default_comment = false,
|
||||||
|
}
|
||||||
|
|
||||||
|
---Update template configuration
|
||||||
|
---@param tbl neogen.TemplateConfig
|
||||||
|
template.config = function(self, tbl)
|
||||||
|
self = vim.tbl_extend("force", self, tbl)
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
template.add_template = function(self, name)
|
||||||
|
local ok, _t = pcall(require, "neogen.templates." .. name)
|
||||||
|
|
||||||
|
if not ok then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
self[name] = _t
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
template.add_default_template = function(self, name)
|
||||||
|
self.annotation_convention = name
|
||||||
|
self = self:add_template(name)
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
return template
|
||||||
Reference in New Issue
Block a user