fix(generator): check template early

This commit is contained in:
kevinhwang91
2022-02-06 19:53:17 +08:00
parent 98c8cbae80
commit be03c71183

View File

@@ -80,17 +80,10 @@ end
---@param required_type string ---@param required_type string
---@return table { line, content }, with line being the line to append the content ---@return table { line, content }, with line being the line to append the content
local function generate_content(parent, data, template, required_type, jump_text) local function generate_content(parent, data, template, required_type, jump_text)
assert(template, "Need a template table")
local row, col = get_place_pos(parent, template.position, template.append, required_type) local row, col = get_place_pos(parent, template.position, template.append, required_type)
local commentstring = vim.trim(vim.bo.commentstring:format("")) local commentstring = vim.trim(vim.bo.commentstring:format(""))
local generated_template local generated_template = template[template.annotation_convention]
if not template.annotation_convention then
-- Default template
generated_template = {{nil, ""}, {"name", " @Summary "}, {"parameters", " @Param "}, {"return", " @Return "}}
else
generated_template = template[template.annotation_convention]
end
local result = {} local result = {}
local prefix = prefix_generator(template, commentstring, col) local prefix = prefix_generator(template, commentstring, col)
@@ -169,7 +162,8 @@ return setmetatable({}, {
return return
end end
typ = (type(typ) ~= "string" or typ == "") and "func" or typ -- Default type typ = (type(typ) ~= "string" or typ == "") and "func" or typ -- Default type
if not language.parent[typ] or not language.data[typ] then local template = language.template
if not language.parent[typ] or not language.data[typ] or not template or not template.annotation_convention then
notify("Type `" .. typ .. "` not supported", vim.log.levels.WARN) notify("Type `" .. typ .. "` not supported", vim.log.levels.WARN)
return return
end end
@@ -184,7 +178,7 @@ return setmetatable({}, {
local jump_text = language.jump_text or conf.jump_text local jump_text = language.jump_text or conf.jump_text
-- Will try to generate the documentation from a template and the data found from the granulator -- Will try to generate the documentation from a template and the data found from the granulator
local row, template_content = generate_content(parent_node, data, language.template, typ, jump_text) local row, template_content = generate_content(parent_node, data, template, typ, jump_text)
local content = {} local content = {}
local marks_pos = {} local marks_pos = {}