This commit is contained in:
hrsh7th
2022-01-25 10:06:36 +09:00
parent 27123b1297
commit 2d67b6dd76
3 changed files with 76 additions and 77 deletions

View File

@@ -260,57 +260,45 @@ core.complete = function(self, ctx)
end
---Update completion menu
core.filter = async.throttle(
setmetatable({
ctx = nil,
}, {
__call = function(this, self)
self.filter.timeout = self.view:visible() and THROTTLE_TIME or 0
core.filter = async.throttle(function(self)
self.filter.timeout = self.view:visible() and THROTTLE_TIME or 0
-- Check context changed.
local ctx = self:get_context()
if this.ctx and not this.ctx:changed(ctx) then
return
end
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
-- Check invalid condition.
local ignore = false
ignore = ignore or not api.is_suitable_mode()
if ignore then
return
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.
---@param e cmp.Entry

View File

@@ -94,6 +94,7 @@ describe('keymap', function()
describe('realworld', function()
before_each(spec.before)
it('#226', function()
keymap.listen('i', '<c-n>', function(_, fallback)
fallback()
@@ -101,6 +102,7 @@ describe('keymap', function()
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))
end)
it('#414', function()
keymap.listen('i', '<M-j>', function()
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)
assert.are.same({ 'aiueo', 'aiueo' }, vim.api.nvim_buf_get_lines(0, 0, -1, true))
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)

View File

@@ -197,36 +197,33 @@ view._get_entries_view = function(self)
end
---On entry change
view.on_entry_change = async.throttle(
function(self)
if not self:visible() then
return
view.on_entry_change = async.throttle(function(self)
if not self:visible() then
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
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)
e:resolve(vim.schedule_wrap(self.resolve_dedup(function()
if not self:visible() then
return
end
e:resolve(vim.schedule_wrap(self.resolve_dedup(function()
if not self:visible() then
return
end
self.docs_view:open(e, self:_get_entries_view():info())
end)))
else
self.docs_view:close()
end
self.docs_view:open(e, self:_get_entries_view():info())
end)))
else
self.docs_view:close()
end
e = e or self:get_first_entry()
if e then
self.ghost_text_view:show(e)
else
self.ghost_text_view:hide()
end
end,
20
)
e = e or self:get_first_entry()
if e then
self.ghost_text_view:show(e)
else
self.ghost_text_view:hide()
end
end, 20)
return view