Fix merge bug
This commit is contained in:
@@ -212,7 +212,7 @@ source README which defines the source name as `buffer`.
|
|||||||
|
|
||||||
Which events should trigger `autocompletion`.
|
Which events should trigger `autocompletion`.
|
||||||
|
|
||||||
If you set this to empty or `nil`, `nvim-cmp` will not perform completion
|
If you set this to empty or `false`, `nvim-cmp` will not perform completion
|
||||||
automatically. You can still use manual completion though (like omni-completion
|
automatically. You can still use manual completion though (like omni-completion
|
||||||
via the `cmp.mapping.complete` function).
|
via the `cmp.mapping.complete` function).
|
||||||
|
|
||||||
|
|||||||
@@ -21,8 +21,8 @@ end
|
|||||||
---@param v2 T
|
---@param v2 T
|
||||||
---@return T
|
---@return T
|
||||||
misc.merge = function(v1, v2)
|
misc.merge = function(v1, v2)
|
||||||
local merge1 = type(v1) == "table" and not vim.tbl_islist(v1)
|
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(v1)
|
local merge2 = type(v2) == "table" and (not vim.tbl_islist(v1) or vim.tbl_isempty(v1))
|
||||||
if merge1 and merge2 then
|
if merge1 and merge2 then
|
||||||
local new_tbl = {}
|
local new_tbl = {}
|
||||||
for k, v in pairs(v2) do
|
for k, v in pairs(v2) do
|
||||||
|
|||||||
29
lua/cmp/utils/misc_spec.lua
Normal file
29
lua/cmp/utils/misc_spec.lua
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
local spec = require('cmp.utils.spec')
|
||||||
|
|
||||||
|
local misc = require('cmp.utils.misc')
|
||||||
|
|
||||||
|
describe('misc', function()
|
||||||
|
before_each(spec.before)
|
||||||
|
|
||||||
|
it('merge', function()
|
||||||
|
local merged
|
||||||
|
merged = misc.merge({
|
||||||
|
a = {}
|
||||||
|
}, {
|
||||||
|
a = {
|
||||||
|
b = 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
assert.are.equal(merged.a.b, 1)
|
||||||
|
merged = misc.merge({
|
||||||
|
a = false
|
||||||
|
}, {
|
||||||
|
a = {
|
||||||
|
b = 1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
assert.are.equal(merged.a, false)
|
||||||
|
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
Reference in New Issue
Block a user