Make template.annotation_convention a standard

The default generator will now use the annotation_convention field in
template in order to use the requested template
This commit is contained in:
Daniel Mathiot
2021-08-23 11:33:08 +02:00
parent dd54ea7708
commit 2eb4f76cc9
3 changed files with 3 additions and 16 deletions

View File

@@ -53,7 +53,7 @@ return {
-- Use default granulator and generator
granulator = nil,
generator = require("neogen.generators.lua"),
generator = nil,
template = {
-- Which annotation convention to use

View File

@@ -10,7 +10,7 @@ neogen.default_generator = function(parent, data, template)
local start_row, start_column, _, _ = ts_utils.get_node_range(parent)
local commentstring, generated_template = vim.trim(vim.api.nvim_buf_get_option(0, "commentstring"):format(""))
if not template then
if not template or not template.annotation_convention then
-- Default template
generated_template = {
{ nil, "" },
@@ -22,7 +22,7 @@ neogen.default_generator = function(parent, data, template)
-- You can also pass a function as a template
generated_template = template(parent, commentstring, data)
else
generated_template = template
generated_template = template[template.annotation_convention]
end
local function parse_generated_template()

View File

@@ -1,13 +0,0 @@
--- 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