Improve completion invoking
This commit is contained in:
@@ -59,7 +59,7 @@ core.ghost_text = function(e)
|
|||||||
if #text > 0 then
|
if #text > 0 then
|
||||||
vim.api.nvim_buf_set_extmark(ctx.bufnr, core.GHOST_TEXT_NS, ctx.cursor.row - 1, ctx.cursor.col - 1, {
|
vim.api.nvim_buf_set_extmark(ctx.bufnr, core.GHOST_TEXT_NS, ctx.cursor.row - 1, ctx.cursor.col - 1, {
|
||||||
right_gravity = false,
|
right_gravity = false,
|
||||||
virt_text = { { text, c.hl_group } },
|
virt_text = { { text, c.hl_group or 'Comment' } },
|
||||||
virt_text_pos = 'overlay',
|
virt_text_pos = 'overlay',
|
||||||
virt_text_win_col = ctx.virtcol - 1,
|
virt_text_win_col = ctx.virtcol - 1,
|
||||||
priority = 1,
|
priority = 1,
|
||||||
@@ -243,7 +243,7 @@ core.complete = function(ctx)
|
|||||||
core.filter()
|
core.filter()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for _, s in ipairs(core.get_sources()) do
|
for _, s in ipairs(core.get_sources({ source.SourceStatus.WAITING, source.SourceStatus.COMPLETED })) do
|
||||||
s:complete(ctx, callback)
|
s:complete(ctx, callback)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -256,17 +256,22 @@ core.filter = async.throttle(function()
|
|||||||
local ctx = core.get_context()
|
local ctx = core.get_context()
|
||||||
|
|
||||||
-- To wait for processing source for that's timeout.
|
-- To wait for processing source for that's timeout.
|
||||||
for _, s in ipairs(core.get_sources({ source.SourceStatus.FETCHING })) do
|
local sources = {}
|
||||||
|
for _, s in ipairs(core.get_sources()) do
|
||||||
local time = core.SOURCE_TIMEOUT - s:get_fetching_time()
|
local time = core.SOURCE_TIMEOUT - s:get_fetching_time()
|
||||||
if time > 0 then
|
if not s.incomplete and time > 0 then
|
||||||
|
if #sources == 0 then
|
||||||
core.filter.stop()
|
core.filter.stop()
|
||||||
core.filter.timeout = time + 1
|
core.filter.timeout = time + 1
|
||||||
core.filter()
|
core.filter()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
|
table.insert(sources, s)
|
||||||
end
|
end
|
||||||
|
|
||||||
core.menu:update(ctx, core.get_sources())
|
core.menu:update(ctx, sources)
|
||||||
core.ghost_text(core.menu:get_first_entry())
|
core.ghost_text(core.menu:get_first_entry())
|
||||||
end, 50)
|
end, 50)
|
||||||
|
|
||||||
@@ -274,7 +279,7 @@ end, 50)
|
|||||||
---@param e cmp.Entry
|
---@param e cmp.Entry
|
||||||
---@param option cmp.ConfirmOption
|
---@param option cmp.ConfirmOption
|
||||||
---@param callback function
|
---@param callback function
|
||||||
core.confirm = vim.schedule_wrap(function(e, option, callback)
|
core.confirm = function(e, option, callback)
|
||||||
if not (e and not e.confirmed) then
|
if not (e and not e.confirmed) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -373,7 +378,7 @@ core.confirm = vim.schedule_wrap(function(e, option, callback)
|
|||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
end)
|
end
|
||||||
|
|
||||||
---Reset current completion state
|
---Reset current completion state
|
||||||
core.reset = function()
|
core.reset = function()
|
||||||
|
|||||||
@@ -127,27 +127,27 @@ keymap.listen = setmetatable({
|
|||||||
existing = existing,
|
existing = existing,
|
||||||
callback = callback,
|
callback = callback,
|
||||||
})
|
})
|
||||||
vim.api.nvim_buf_set_keymap(0, mode, keys, ('v:lua.cmp.utils.keymap.listen.expr("%s", "%s")'):format(mode, str.escape(keymap.escape(keys), { '"' })), {
|
vim.api.nvim_buf_set_keymap(0, mode, keys, ('<Cmd>call v:lua.cmp.utils.keymap.listen.run("%s", "%s")<CR>'):format(mode, str.escape(keymap.escape(keys), { '"' })), {
|
||||||
expr = true,
|
expr = false,
|
||||||
nowait = true,
|
nowait = true,
|
||||||
noremap = true,
|
noremap = true,
|
||||||
silent = true,
|
silent = true,
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
misc.set(_G, { 'cmp', 'utils', 'keymap', 'listen', 'expr' }, function(mode, keys)
|
misc.set(_G, { 'cmp', 'utils', 'keymap', 'listen', 'run' }, function(mode, keys)
|
||||||
local bufnr = vim.api.nvim_get_current_buf()
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
|
||||||
local existing = keymap.listen.cache:get({ mode, bufnr, keys }).existing
|
local existing = keymap.listen.cache:get({ mode, bufnr, keys }).existing
|
||||||
local callback = keymap.listen.cache:get({ mode, bufnr, keys }).callback
|
local callback = keymap.listen.cache:get({ mode, bufnr, keys }).callback
|
||||||
callback(keys, function()
|
callback(keys, function()
|
||||||
vim.api.nvim_buf_set_keymap(0, mode, '<Plug>(cmp-utils-keymap:_)', existing.rhs, {
|
vim.api.nvim_buf_set_keymap(0, mode, '<Plug>(cmp-utils-keymap-listen-run:_)', existing.rhs, {
|
||||||
expr = existing.expr ~= 0,
|
expr = existing.expr ~= 0,
|
||||||
noremap = existing.noremap ~= 0,
|
noremap = existing.noremap ~= 0,
|
||||||
script = existing.script ~= 0,
|
script = existing.script ~= 0,
|
||||||
silent = true,
|
silent = true,
|
||||||
})
|
})
|
||||||
vim.fn.feedkeys(keymap.t('<Plug>(cmp-utils-keymap:_)'), '')
|
vim.fn.feedkeys(keymap.t('<Plug>(cmp-utils-keymap-listen-run:_)'), '')
|
||||||
end)
|
end)
|
||||||
return keymap.t('<Ignore>')
|
return keymap.t('<Ignore>')
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user