From 5a80cd4eca61cd4f5e10165bbb5dc5411d6a5a76 Mon Sep 17 00:00:00 2001 From: hrsh7th <629908+hrsh7th@users.noreply.github.com> Date: Sun, 7 May 2023 14:59:51 +0900 Subject: [PATCH] Fix #897 --- lua/cmp/utils/misc.lua | 50 +++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/lua/cmp/utils/misc.lua b/lua/cmp/utils/misc.lua index 9f8a40d6c..9e69b4fb0 100644 --- a/lua/cmp/utils/misc.lua +++ b/lua/cmp/utils/misc.lua @@ -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