mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-06-28 11:24:14 +00:00
Merge lists in lazy.core.util.merge
This commit is contained in:
parent
666ed7bf73
commit
ea2ba4df23
2 changed files with 15 additions and 1 deletions
|
@ -302,6 +302,10 @@ local function can_merge(v)
|
|||
return type(v) == "table" and (vim.tbl_isempty(v) or not M.is_list(v))
|
||||
end
|
||||
|
||||
local function can_merge_list(v)
|
||||
return type(v) == "table" and M.is_list(v)
|
||||
end
|
||||
|
||||
--- 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.
|
||||
--- Values will me merged in-place in the first left-most table. If you want the result to be in
|
||||
|
@ -324,6 +328,12 @@ function M.merge(...)
|
|||
for k, v in pairs(value) do
|
||||
ret[k] = M.merge(ret[k], v)
|
||||
end
|
||||
elseif can_merge_list(ret) and can_merge_list(value) then
|
||||
for _, v in ipairs(value) do
|
||||
if not vim.tbl_contains(ret, v) then
|
||||
ret[#ret+1] = v
|
||||
end
|
||||
end
|
||||
elseif value == vim.NIL then
|
||||
ret = nil
|
||||
else
|
||||
|
|
|
@ -145,7 +145,11 @@ describe("util", function()
|
|||
},
|
||||
{
|
||||
input = { { a = { 1, 2 } }, { a = { 3 } } },
|
||||
output = { a = { 3 } },
|
||||
output = { a = { 1, 2, 3 } },
|
||||
},
|
||||
{
|
||||
input = { { a = { 1, 2 } }, { a = { 1, 3 } } },
|
||||
output = { a = { 1, 2, 3 } },
|
||||
},
|
||||
{
|
||||
input = { { b = { 1, 2 } }, { a = { 3 }, b = vim.NIL } },
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue