Skip to content

Commit

Permalink
Fix #897
Browse files Browse the repository at this point in the history
  • Loading branch information
hrsh7th committed May 7, 2023
1 parent 1cad30f commit 5a80cd4
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions lua/cmp/utils/misc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,42 +74,38 @@ misc.none = vim.NIL

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

if tbl1 == misc.none then
return nil
elseif tbl1 == nil then
return misc.merge(tbl2, {})
else
return tbl1
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
end

---Generate id for group name
Expand Down

0 comments on commit 5a80cd4

Please sign in to comment.