This commit is contained in:
hrsh7th
2023-05-07 14:59:51 +09:00
parent 1cad30fcff
commit 5a80cd4eca

View File

@@ -74,42 +74,38 @@ misc.none = vim.NIL
---Merge two tables recursively ---Merge two tables recursively
---@generic T ---@generic T
---@param v1 T ---@param tbl1 T
---@param v2 T ---@param tbl2 T
---@return T ---@return T
misc.merge = function(v1, v2) misc.merge = function(tbl1, tbl2)
local merge1 = type(v1) == 'table' and (not vim.tbl_islist(v1) or vim.tbl_isempty(v1)) local is_dict1 = type(tbl1) == 'table' and (not vim.tbl_islist(tbl1) or vim.tbl_isempty(tbl1))
local merge2 = type(v2) == 'table' and (not vim.tbl_islist(v2) or vim.tbl_isempty(v2)) local is_dict2 = type(tbl2) == 'table' and (not vim.tbl_islist(tbl2) or vim.tbl_isempty(tbl2))
if merge1 and merge2 then if is_dict1 and is_dict2 then
local new_tbl = {} local new_tbl = {}
for k, v in pairs(v2) do for k, v in pairs(tbl2) do
new_tbl[k] = misc.merge(v1[k], v) if tbl1[k] ~= misc.none then
new_tbl[k] = misc.merge(tbl1[k], v)
end end
for k, v in pairs(v1) do end
if v2[k] == nil and v ~= misc.none then for k, v in pairs(tbl1) do
if tbl2[k] == nil then
if v ~= misc.none then
new_tbl[k] = v new_tbl[k] = v
else
new_tbl[k] = nil
end
end end
end end
return new_tbl return new_tbl
end end
if v1 == misc.none then
return nil
end
if v1 == nil then
if v2 == misc.none then
return nil
else
return v2
end
end
if v1 == true then
if merge2 then
return v2
end
return {}
end
return v1 if tbl1 == misc.none then
return nil
elseif tbl1 == nil then
return misc.merge(tbl2, {})
else
return tbl1
end
end end
---Generate id for group name ---Generate id for group name