Fix #436
This commit is contained in:
@@ -35,7 +35,7 @@ compare.recently_used = setmetatable({
|
||||
records = {},
|
||||
add_entry = function(self, e)
|
||||
self.records[e.completion_item.label] = vim.loop.now()
|
||||
end
|
||||
end,
|
||||
}, {
|
||||
__call = function(self, entry1, entry2)
|
||||
local t1 = self.records[entry1.completion_item.label] or -1
|
||||
@@ -43,7 +43,7 @@ compare.recently_used = setmetatable({
|
||||
if t1 ~= t2 then
|
||||
return t1 > t2
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
-- kind
|
||||
|
||||
@@ -91,7 +91,7 @@ return function()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end
|
||||
end,
|
||||
}),
|
||||
['<S-Tab>'] = mapping({
|
||||
c = function(fallback)
|
||||
@@ -105,7 +105,7 @@ return function()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end
|
||||
end,
|
||||
}),
|
||||
['<C-n>'] = mapping(mapping.select_next_item({ behavior = types.cmp.SelectBehavior.Insert }), { 'i', 'c' }),
|
||||
['<C-p>'] = mapping(mapping.select_prev_item({ behavior = types.cmp.SelectBehavior.Insert }), { 'i', 'c' }),
|
||||
|
||||
@@ -202,7 +202,7 @@ core.autoindent = function(self, trigger_event, callback)
|
||||
if trigger_event ~= types.cmp.TriggerEvent.TextChanged then
|
||||
return callback()
|
||||
end
|
||||
if not api.is_insert_mode() then
|
||||
if not api.is_insert_mode() then
|
||||
return callback()
|
||||
end
|
||||
|
||||
|
||||
@@ -215,14 +215,31 @@ keymap.listen = setmetatable({
|
||||
local bufnr = vim.api.nvim_get_current_buf()
|
||||
local existing = keymap.find_map_by_lhs(mode, keys)
|
||||
|
||||
local done = true
|
||||
done = done and string.match(existing.rhs, vim.pesc('v:lua.cmp.utils.keymap.listen.run'))
|
||||
done = done and self.cache:get({ 'id', mode, bufnr, keys }) ~= nil
|
||||
if done then
|
||||
return
|
||||
local cur_definition = self.cache:get({ 'definition', self.cache:get({ 'id', mode, bufnr, keys }) or '' })
|
||||
if cur_definition then
|
||||
local same = true
|
||||
same = same and existing
|
||||
same = same and cur_definition.existing.lhs == existing.lhs
|
||||
same = same and cur_definition.existing.rhs == existing.rhs
|
||||
same = same and cur_definition.existing.expr == existing.expr
|
||||
same = same and cur_definition.existing.noremap == existing.noremap
|
||||
same = same and cur_definition.existing.script == existing.script
|
||||
if not existing or same then
|
||||
return
|
||||
end
|
||||
end
|
||||
self.cache:set({ 'id', mode, bufnr, keys }, misc.id('cmp.utils.keymap.listen'))
|
||||
|
||||
existing = existing or {
|
||||
lhs = keys,
|
||||
rhs = keys,
|
||||
expr = 0,
|
||||
script = 0,
|
||||
noremap = 1,
|
||||
nowait = 0,
|
||||
silent = 1,
|
||||
}
|
||||
|
||||
local fallback = keymap.evacuate(mode, keys)
|
||||
vim.api.nvim_buf_set_keymap(0, mode, keys, ('<Cmd>call v:lua.cmp.utils.keymap.listen.run(%s)<CR>'):format(self.cache:get({ 'id', mode, bufnr, keys })), {
|
||||
expr = false,
|
||||
@@ -260,6 +277,9 @@ end)
|
||||
---@return { keys: string, mode: string }
|
||||
keymap.evacuate = function(mode, lhs)
|
||||
local map = keymap.find_map_by_lhs(mode, lhs)
|
||||
if not map then
|
||||
return { keys = lhs, mode = 'itn' }
|
||||
end
|
||||
|
||||
-- Keep existing mapping as <Plug> mapping. We escape fisrt recursive key sequence. See `:help recursive_mapping`)
|
||||
local rhs = map.rhs
|
||||
@@ -322,23 +342,21 @@ end
|
||||
keymap.find_map_by_lhs = function(mode, lhs)
|
||||
for _, map in ipairs(vim.api.nvim_buf_get_keymap(0, mode)) do
|
||||
if keymap.equals(map.lhs, lhs) then
|
||||
if string.match(map.rhs, vim.pesc('v:lua.cmp.utils.keymap.listen.run')) then
|
||||
return nil
|
||||
end
|
||||
return map
|
||||
end
|
||||
end
|
||||
|
||||
for _, map in ipairs(vim.api.nvim_get_keymap(mode)) do
|
||||
if keymap.equals(map.lhs, lhs) then
|
||||
if string.match(map.rhs, vim.pesc('v:lua.cmp.utils.keymap.listen.run')) then
|
||||
return nil
|
||||
end
|
||||
return map
|
||||
end
|
||||
end
|
||||
return {
|
||||
lhs = lhs,
|
||||
rhs = lhs,
|
||||
expr = 0,
|
||||
script = 0,
|
||||
noremap = 1,
|
||||
nowait = 0,
|
||||
silent = 1,
|
||||
}
|
||||
end
|
||||
|
||||
keymap.spec = function()
|
||||
|
||||
Reference in New Issue
Block a user