fix: Better use of nested template

This commit is contained in:
danymat
2022-01-22 20:31:33 +01:00
parent bf1d7e25c8
commit e682494f13

View File

@@ -127,7 +127,7 @@ neogen.default_generator = function(parent, data, template, required_type)
local inserted = conditional_prefix_inserter(prefix, formatted_string:format(value)) local inserted = conditional_prefix_inserter(prefix, formatted_string:format(value))
table.insert(result, inserted) table.insert(result, inserted)
end end
elseif type(inserted_type) == "table" and #inserted_type >= 1 then elseif type(inserted_type) == "table" and data[opts.required] then
-- First item in the template item can be a table. -- First item in the template item can be a table.
-- in this case, the template will use provided types to generate the line. -- in this case, the template will use provided types to generate the line.
-- e.g {{ "type", "parameter"}, "* @type {%s} %s"} -- e.g {{ "type", "parameter"}, "* @type {%s} %s"}
@@ -135,26 +135,23 @@ neogen.default_generator = function(parent, data, template, required_type)
-- If one item is missing, it'll use the required option to iterate -- If one item is missing, it'll use the required option to iterate
-- and will replace the missing item with default jump_text -- and will replace the missing item with default jump_text
if data[opts.required] or (data[inserted_type[1]] and opts.required == nil) then for _, tbl in pairs(data[opts.required]) do
local count = opts.required and #data[opts.required] or #data[inserted_type[1]] local _values = {}
for i = 1, count do for _, v in ipairs(inserted_type) do
local _values = {} if tbl[v] then
for _, v in ipairs(inserted_type) do table.insert(_values, tbl[v][1])
if data[v] and data[v][i] then else
table.insert(_values, data[v][i]) local jump_text = neogen.configuration.jump_text
else table.insert(_values, jump_text)
local jump_text = neogen.configuration.jump_text
table.insert(_values, jump_text)
end
end
if not vim.tbl_isempty(_values) then
local inserted = conditional_prefix_inserter(
prefix,
formatted_string:format(unpack(_values))
)
table.insert(result, inserted)
end end
end end
if not vim.tbl_isempty(_values) then
local inserted = conditional_prefix_inserter(
prefix,
formatted_string:format(unpack(_values))
)
table.insert(result, inserted)
end
end end
end end
end end