Fix #756
This commit is contained in:
@@ -260,57 +260,45 @@ core.complete = function(self, ctx)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Update completion menu
|
---Update completion menu
|
||||||
core.filter = async.throttle(
|
core.filter = async.throttle(function(self)
|
||||||
setmetatable({
|
self.filter.timeout = self.view:visible() and THROTTLE_TIME or 0
|
||||||
ctx = nil,
|
|
||||||
}, {
|
|
||||||
__call = function(this, self)
|
|
||||||
self.filter.timeout = self.view:visible() and THROTTLE_TIME or 0
|
|
||||||
|
|
||||||
-- Check context changed.
|
-- Check invalid condition.
|
||||||
local ctx = self:get_context()
|
local ignore = false
|
||||||
if this.ctx and not this.ctx:changed(ctx) then
|
ignore = ignore or not api.is_suitable_mode()
|
||||||
return
|
if ignore then
|
||||||
end
|
return
|
||||||
this.ctx = ctx
|
|
||||||
|
|
||||||
-- Check invalid condition.
|
|
||||||
local ignore = false
|
|
||||||
ignore = ignore or not api.is_suitable_mode()
|
|
||||||
if ignore then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Check fetching sources.
|
|
||||||
local sources = {}
|
|
||||||
for _, s in ipairs(self:get_sources({ source.SourceStatus.FETCHING, source.SourceStatus.COMPLETED })) do
|
|
||||||
if not s.incomplete and SOURCE_TIMEOUT > s:get_fetching_time() then
|
|
||||||
-- Reserve filter call for timeout.
|
|
||||||
self.filter.timeout = SOURCE_TIMEOUT - s:get_fetching_time()
|
|
||||||
self:filter()
|
|
||||||
break
|
|
||||||
end
|
|
||||||
table.insert(sources, s)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Display completion results.
|
|
||||||
self.view:open(ctx, sources)
|
|
||||||
|
|
||||||
-- Check onetime config.
|
|
||||||
if #self:get_sources(function(s)
|
|
||||||
if s.status == source.SourceStatus.FETCHING then
|
|
||||||
return true
|
|
||||||
elseif #s:get_entries(ctx) > 0 then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end) == 0 then
|
|
||||||
config.set_onetime({})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
}),
|
|
||||||
THROTTLE_TIME
|
-- Check fetching sources.
|
||||||
)
|
local sources = {}
|
||||||
|
for _, s in ipairs(self:get_sources({ source.SourceStatus.FETCHING, source.SourceStatus.COMPLETED })) do
|
||||||
|
if not s.incomplete and SOURCE_TIMEOUT > s:get_fetching_time() then
|
||||||
|
-- Reserve filter call for timeout.
|
||||||
|
self.filter.timeout = SOURCE_TIMEOUT - s:get_fetching_time()
|
||||||
|
self:filter()
|
||||||
|
break
|
||||||
|
end
|
||||||
|
table.insert(sources, s)
|
||||||
|
end
|
||||||
|
|
||||||
|
local ctx = self:get_context()
|
||||||
|
|
||||||
|
-- Display completion results.
|
||||||
|
self.view:open(ctx, sources)
|
||||||
|
|
||||||
|
-- Check onetime config.
|
||||||
|
if #self:get_sources(function(s)
|
||||||
|
if s.status == source.SourceStatus.FETCHING then
|
||||||
|
return true
|
||||||
|
elseif #s:get_entries(ctx) > 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end) == 0 then
|
||||||
|
config.set_onetime({})
|
||||||
|
end
|
||||||
|
end, THROTTLE_TIME)
|
||||||
|
|
||||||
---Confirm completion.
|
---Confirm completion.
|
||||||
---@param e cmp.Entry
|
---@param e cmp.Entry
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ describe('keymap', function()
|
|||||||
|
|
||||||
describe('realworld', function()
|
describe('realworld', function()
|
||||||
before_each(spec.before)
|
before_each(spec.before)
|
||||||
|
|
||||||
it('#226', function()
|
it('#226', function()
|
||||||
keymap.listen('i', '<c-n>', function(_, fallback)
|
keymap.listen('i', '<c-n>', function(_, fallback)
|
||||||
fallback()
|
fallback()
|
||||||
@@ -101,6 +102,7 @@ describe('keymap', function()
|
|||||||
vim.api.nvim_feedkeys(keymap.t('iaiueo<CR>a<C-n><C-n>'), 'tx', true)
|
vim.api.nvim_feedkeys(keymap.t('iaiueo<CR>a<C-n><C-n>'), 'tx', true)
|
||||||
assert.are.same({ 'aiueo', 'aiueo' }, vim.api.nvim_buf_get_lines(0, 0, -1, true))
|
assert.are.same({ 'aiueo', 'aiueo' }, vim.api.nvim_buf_get_lines(0, 0, -1, true))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
it('#414', function()
|
it('#414', function()
|
||||||
keymap.listen('i', '<M-j>', function()
|
keymap.listen('i', '<M-j>', function()
|
||||||
vim.api.nvim_feedkeys(keymap.t('<C-n>'), 'int', true)
|
vim.api.nvim_feedkeys(keymap.t('<C-n>'), 'int', true)
|
||||||
@@ -108,5 +110,17 @@ describe('keymap', function()
|
|||||||
vim.api.nvim_feedkeys(keymap.t('iaiueo<CR>a<M-j><M-j>'), 'tx', true)
|
vim.api.nvim_feedkeys(keymap.t('iaiueo<CR>a<M-j><M-j>'), 'tx', true)
|
||||||
assert.are.same({ 'aiueo', 'aiueo' }, vim.api.nvim_buf_get_lines(0, 0, -1, true))
|
assert.are.same({ 'aiueo', 'aiueo' }, vim.api.nvim_buf_get_lines(0, 0, -1, true))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- it('#744', function()
|
||||||
|
-- vim.api.nvim_buf_set_keymap(0, 'i', '<C-r>', 'recursive', {
|
||||||
|
-- noremap = true
|
||||||
|
-- })
|
||||||
|
-- vim.api.nvim_buf_set_keymap(0, 'i', '<CR>', '<CR>recursive', {
|
||||||
|
-- noremap = false
|
||||||
|
-- })
|
||||||
|
-- keymap.listen('i', '<CR>', function(_, fallback) fallback() end)
|
||||||
|
-- feedkeys.call(keymap.t('i<CR>'), 'tx')
|
||||||
|
-- assert.are.same({ '', 'recursive' }, vim.api.nvim_buf_get_lines(0, 0, -1, true))
|
||||||
|
-- end)
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|||||||
@@ -197,36 +197,33 @@ view._get_entries_view = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---On entry change
|
---On entry change
|
||||||
view.on_entry_change = async.throttle(
|
view.on_entry_change = async.throttle(function(self)
|
||||||
function(self)
|
if not self:visible() then
|
||||||
if not self:visible() then
|
return
|
||||||
return
|
end
|
||||||
|
local e = self:get_selected_entry()
|
||||||
|
if e then
|
||||||
|
for _, c in ipairs(config.get().confirmation.get_commit_characters(e:get_commit_characters())) do
|
||||||
|
keymap.listen('i', c, function(...)
|
||||||
|
self.event:emit('keymap', ...)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
local e = self:get_selected_entry()
|
e:resolve(vim.schedule_wrap(self.resolve_dedup(function()
|
||||||
if e then
|
if not self:visible() then
|
||||||
for _, c in ipairs(config.get().confirmation.get_commit_characters(e:get_commit_characters())) do
|
return
|
||||||
keymap.listen('i', c, function(...)
|
|
||||||
self.event:emit('keymap', ...)
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
e:resolve(vim.schedule_wrap(self.resolve_dedup(function()
|
self.docs_view:open(e, self:_get_entries_view():info())
|
||||||
if not self:visible() then
|
end)))
|
||||||
return
|
else
|
||||||
end
|
self.docs_view:close()
|
||||||
self.docs_view:open(e, self:_get_entries_view():info())
|
end
|
||||||
end)))
|
|
||||||
else
|
|
||||||
self.docs_view:close()
|
|
||||||
end
|
|
||||||
|
|
||||||
e = e or self:get_first_entry()
|
e = e or self:get_first_entry()
|
||||||
if e then
|
if e then
|
||||||
self.ghost_text_view:show(e)
|
self.ghost_text_view:show(e)
|
||||||
else
|
else
|
||||||
self.ghost_text_view:hide()
|
self.ghost_text_view:hide()
|
||||||
end
|
end
|
||||||
end,
|
end, 20)
|
||||||
20
|
|
||||||
)
|
|
||||||
|
|
||||||
return view
|
return view
|
||||||
|
|||||||
Reference in New Issue
Block a user