Specify template convention in lua
This commit is contained in:
@@ -139,10 +139,14 @@ generator = nil,
|
|||||||
|
|
||||||
-- Template to use with the generator. (More on this below)
|
-- Template to use with the generator. (More on this below)
|
||||||
template = {
|
template = {
|
||||||
|
-- Which annotation convention to use
|
||||||
|
annotation_convention = "emmylua",
|
||||||
|
emmylua = {
|
||||||
{ nil, "- " },
|
{ nil, "- " },
|
||||||
{ "parameters", "- @param %s any" },
|
{ "parameters", "- @param %s any" },
|
||||||
{ "vararg", "- @vararg any" },
|
{ "vararg", "- @vararg any" },
|
||||||
{ "return_statement", "- @return any" }
|
{ "return_statement", "- @return any" }
|
||||||
|
}
|
||||||
},
|
},
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ require("neogen.locators.default")
|
|||||||
require("neogen.granulators.default")
|
require("neogen.granulators.default")
|
||||||
require("neogen.generators.default")
|
require("neogen.generators.default")
|
||||||
|
|
||||||
|
|
||||||
neogen.auto_generate = function(custom_template)
|
neogen.auto_generate = function(custom_template)
|
||||||
vim.treesitter.get_parser(0):for_each_tree(function(tree, language_tree)
|
vim.treesitter.get_parser(0):for_each_tree(function(tree, language_tree)
|
||||||
local language = neogen.configuration.languages[language_tree:lang()]
|
local language = neogen.configuration.languages[language_tree:lang()]
|
||||||
@@ -47,7 +46,7 @@ neogen.auto_generate = function(custom_template)
|
|||||||
-- Place cursor after annotations ans start editing
|
-- Place cursor after annotations ans start editing
|
||||||
if neogen.configuration.input_after_comment == true then
|
if neogen.configuration.input_after_comment == true then
|
||||||
vim.fn.cursor(to_place + 1, start_column)
|
vim.fn.cursor(to_place + 1, start_column)
|
||||||
vim.api.nvim_command('startinsert!')
|
vim.api.nvim_command("startinsert!")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ return {
|
|||||||
return {
|
return {
|
||||||
parameters = regular_params,
|
parameters = regular_params,
|
||||||
vararg = varargs,
|
vararg = varargs,
|
||||||
return_statement = return_statement
|
return_statement = return_statement,
|
||||||
}
|
}
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
@@ -53,12 +53,16 @@ return {
|
|||||||
|
|
||||||
-- Use default granulator and generator
|
-- Use default granulator and generator
|
||||||
granulator = nil,
|
granulator = nil,
|
||||||
generator = nil,
|
generator = require("neogen.generators.lua"),
|
||||||
|
|
||||||
template = {
|
template = {
|
||||||
|
-- Which annotation convention to use
|
||||||
|
annotation_convention = "emmylua",
|
||||||
|
emmylua = {
|
||||||
{ nil, "- " },
|
{ nil, "- " },
|
||||||
{ "parameters", "- @param %s any" },
|
{ "parameters", "- @param %s any" },
|
||||||
{ "vararg", "- @vararg any" },
|
{ "vararg", "- @vararg any" },
|
||||||
{ "return_statement", "- @return any" }
|
{ "return_statement", "- @return any" },
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
13
lua/neogen/generators/lua.lua
Normal file
13
lua/neogen/generators/lua.lua
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
--- Uses the specified annotation convention in template, an will use the default generator
|
||||||
|
return function(parent, data, template)
|
||||||
|
-- Uses emmylua template by default
|
||||||
|
if template.annotation_convention == nil then
|
||||||
|
template = template["emmylua"]
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Uses the template annotation convention specified in config
|
||||||
|
template = template[template.annotation_convention]
|
||||||
|
if template ~= nil then
|
||||||
|
return neogen.default_generator(parent, data, template)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user