mirror of https://github.com/folke/lazy.nvim.git
refactor: removed special `__merge` functionality
This commit is contained in:
parent
2128ca90fb
commit
784bb3c100
|
@ -298,27 +298,10 @@ function M.debug(msg, opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local MERGE = "__merge"
|
|
||||||
|
|
||||||
local function can_merge(v)
|
local function can_merge(v)
|
||||||
return type(v) == "table" and (vim.tbl_isempty(v) or not M.is_list(v))
|
return type(v) == "table" and (vim.tbl_isempty(v) or not M.is_list(v))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function can_extend(v)
|
|
||||||
return type(v) == "table" and (vim.tbl_isempty(v) or M.is_list(v))
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param v any|{__merge:boolean}
|
|
||||||
---@param merge? boolean
|
|
||||||
---@return boolean?
|
|
||||||
local function check_merge(v, merge)
|
|
||||||
if type(v) == "table" and v[MERGE] ~= nil then
|
|
||||||
merge = v[MERGE]
|
|
||||||
v[MERGE] = nil
|
|
||||||
end
|
|
||||||
return merge
|
|
||||||
end
|
|
||||||
|
|
||||||
--- Merges the values similar to vim.tbl_deep_extend with the **force** behavior,
|
--- Merges the values similar to vim.tbl_deep_extend with the **force** behavior,
|
||||||
--- but the values can be any type, in which case they override the values on the left.
|
--- but the values can be any type, in which case they override the values on the left.
|
||||||
--- Values will me merged in-place in the first left-most table. If you want the result to be in
|
--- Values will me merged in-place in the first left-most table. If you want the result to be in
|
||||||
|
@ -335,19 +318,12 @@ function M.merge(...)
|
||||||
ret = nil
|
ret = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
local merge = check_merge(ret)
|
|
||||||
|
|
||||||
for i = 2, #values, 1 do
|
for i = 2, #values, 1 do
|
||||||
local value = values[i]
|
local value = values[i]
|
||||||
merge = check_merge(value, merge)
|
if can_merge(ret) and can_merge(value) then
|
||||||
if can_merge(ret) and can_merge(value) and merge ~= false then
|
|
||||||
for k, v in pairs(value) do
|
for k, v in pairs(value) do
|
||||||
ret[k] = M.merge(ret[k], v)
|
ret[k] = M.merge(ret[k], v)
|
||||||
end
|
end
|
||||||
elseif can_extend(ret) and can_extend(value) and merge then
|
|
||||||
for _, v in ipairs(value) do
|
|
||||||
ret[#ret + 1] = v
|
|
||||||
end
|
|
||||||
elseif value == vim.NIL then
|
elseif value == vim.NIL then
|
||||||
ret = nil
|
ret = nil
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue