Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
231 lines
5.0 KiB
Lua
231 lines
5.0 KiB
Lua
local types = require('cmp.types')
|
|
local misc = require('cmp.utils.misc')
|
|
local keymap = require('cmp.utils.keymap')
|
|
|
|
local function merge_keymaps(base, override)
|
|
local normalized_base = {}
|
|
for k, v in pairs(base) do
|
|
normalized_base[keymap.normalize(k)] = v
|
|
end
|
|
|
|
local normalized_override = {}
|
|
for k, v in pairs(override) do
|
|
normalized_override[keymap.normalize(k)] = v
|
|
end
|
|
|
|
return misc.merge(normalized_base, normalized_override)
|
|
end
|
|
|
|
local mapping = setmetatable({}, {
|
|
__call = function(_, invoke, modes)
|
|
if type(invoke) == 'function' then
|
|
local map = {}
|
|
for _, mode in ipairs(modes or { 'i' }) do
|
|
map[mode] = invoke
|
|
end
|
|
return map
|
|
end
|
|
return invoke
|
|
end,
|
|
})
|
|
|
|
---Mapping preset configuration.
|
|
mapping.preset = {}
|
|
|
|
---Mapping preset insert-mode configuration.
|
|
mapping.preset.insert = function(override)
|
|
return merge_keymaps(override or {}, {
|
|
['<Down>'] = {
|
|
i = mapping.select_next_item({ behavior = types.cmp.SelectBehavior.Select }),
|
|
},
|
|
['<Up>'] = {
|
|
i = mapping.select_prev_item({ behavior = types.cmp.SelectBehavior.Select }),
|
|
},
|
|
['<C-n>'] = {
|
|
i = function()
|
|
local cmp = require('cmp')
|
|
if cmp.visible() then
|
|
cmp.select_next_item({ behavior = types.cmp.SelectBehavior.Insert })
|
|
else
|
|
cmp.complete()
|
|
end
|
|
end,
|
|
},
|
|
['<C-p>'] = {
|
|
i = function()
|
|
local cmp = require('cmp')
|
|
if cmp.visible() then
|
|
cmp.select_prev_item({ behavior = types.cmp.SelectBehavior.Insert })
|
|
else
|
|
cmp.complete()
|
|
end
|
|
end,
|
|
},
|
|
['<C-y>'] = {
|
|
i = mapping.confirm({ select = false }),
|
|
},
|
|
['<C-e>'] = {
|
|
i = mapping.abort(),
|
|
},
|
|
})
|
|
end
|
|
|
|
---Mapping preset cmdline-mode configuration.
|
|
mapping.preset.cmdline = function(override)
|
|
return merge_keymaps(override or {}, {
|
|
['<C-z>'] = {
|
|
c = function()
|
|
local cmp = require('cmp')
|
|
if cmp.visible() then
|
|
cmp.select_next_item()
|
|
else
|
|
cmp.complete()
|
|
end
|
|
end,
|
|
},
|
|
['<Tab>'] = {
|
|
c = function()
|
|
local cmp = require('cmp')
|
|
if cmp.visible() then
|
|
cmp.select_next_item()
|
|
else
|
|
cmp.complete()
|
|
end
|
|
end,
|
|
},
|
|
['<S-Tab>'] = {
|
|
c = function()
|
|
local cmp = require('cmp')
|
|
if cmp.visible() then
|
|
cmp.select_prev_item()
|
|
else
|
|
cmp.complete()
|
|
end
|
|
end,
|
|
},
|
|
['<C-n>'] = {
|
|
c = function(fallback)
|
|
local cmp = require('cmp')
|
|
if cmp.visible() then
|
|
cmp.select_next_item()
|
|
else
|
|
fallback()
|
|
end
|
|
end,
|
|
},
|
|
['<C-p>'] = {
|
|
c = function(fallback)
|
|
local cmp = require('cmp')
|
|
if cmp.visible() then
|
|
cmp.select_prev_item()
|
|
else
|
|
fallback()
|
|
end
|
|
end,
|
|
},
|
|
['<C-e>'] = {
|
|
c = mapping.abort(),
|
|
},
|
|
['<C-y>'] = {
|
|
c = mapping.confirm({ select = false }),
|
|
},
|
|
})
|
|
end
|
|
|
|
---Invoke completion
|
|
---@param option? cmp.CompleteParams
|
|
mapping.complete = function(option)
|
|
return function(fallback)
|
|
if not require('cmp').complete(option) then
|
|
fallback()
|
|
end
|
|
end
|
|
end
|
|
|
|
---Complete common string.
|
|
mapping.complete_common_string = function()
|
|
return function(fallback)
|
|
if not require('cmp').complete_common_string() then
|
|
fallback()
|
|
end
|
|
end
|
|
end
|
|
|
|
---Close current completion menu if it displayed.
|
|
mapping.close = function()
|
|
return function(fallback)
|
|
if not require('cmp').close() then
|
|
fallback()
|
|
end
|
|
end
|
|
end
|
|
|
|
---Abort current completion menu if it displayed.
|
|
mapping.abort = function()
|
|
return function(fallback)
|
|
if not require('cmp').abort() then
|
|
fallback()
|
|
end
|
|
end
|
|
end
|
|
|
|
---Scroll documentation window.
|
|
mapping.scroll_docs = function(delta)
|
|
return function(fallback)
|
|
if not require('cmp').scroll_docs(delta) then
|
|
fallback()
|
|
end
|
|
end
|
|
end
|
|
|
|
--- Opens the documentation window.
|
|
mapping.open_docs = function()
|
|
return function(fallback)
|
|
if not require('cmp').open_docs() then
|
|
fallback()
|
|
end
|
|
end
|
|
end
|
|
|
|
--- Close the documentation window.
|
|
mapping.close_docs = function()
|
|
return function(fallback)
|
|
if not require('cmp').close_docs() then
|
|
fallback()
|
|
end
|
|
end
|
|
end
|
|
|
|
---Select next completion item.
|
|
mapping.select_next_item = function(option)
|
|
return function(fallback)
|
|
if not require('cmp').select_next_item(option) then
|
|
local release = require('cmp').core:suspend()
|
|
fallback()
|
|
vim.schedule(release)
|
|
end
|
|
end
|
|
end
|
|
|
|
---Select prev completion item.
|
|
mapping.select_prev_item = function(option)
|
|
return function(fallback)
|
|
if not require('cmp').select_prev_item(option) then
|
|
local release = require('cmp').core:suspend()
|
|
fallback()
|
|
vim.schedule(release)
|
|
end
|
|
end
|
|
end
|
|
|
|
---Confirm selection
|
|
mapping.confirm = function(option)
|
|
return function(fallback)
|
|
if not require('cmp').confirm(option) then
|
|
fallback()
|
|
end
|
|
end
|
|
end
|
|
|
|
return mapping
|