From 2eb4f76cc9eed3606544354c2cd6218944f0b7cb Mon Sep 17 00:00:00 2001 From: Daniel Mathiot Date: Mon, 23 Aug 2021 11:33:08 +0200 Subject: [PATCH] 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 --- lua/neogen/configurations/lua.lua | 2 +- lua/neogen/generators/default.lua | 4 ++-- lua/neogen/generators/lua.lua | 13 ------------- 3 files changed, 3 insertions(+), 16 deletions(-) delete mode 100644 lua/neogen/generators/lua.lua diff --git a/lua/neogen/configurations/lua.lua b/lua/neogen/configurations/lua.lua index 62a7ba5..dad19fe 100644 --- a/lua/neogen/configurations/lua.lua +++ b/lua/neogen/configurations/lua.lua @@ -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 diff --git a/lua/neogen/generators/default.lua b/lua/neogen/generators/default.lua index aa5e80f..6e44331 100644 --- a/lua/neogen/generators/default.lua +++ b/lua/neogen/generators/default.lua @@ -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() diff --git a/lua/neogen/generators/lua.lua b/lua/neogen/generators/lua.lua deleted file mode 100644 index a94e6dc..0000000 --- a/lua/neogen/generators/lua.lua +++ /dev/null @@ -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