@@ -74,9 +74,10 @@ end
|
|||||||
---Suspend completion
|
---Suspend completion
|
||||||
core.suspend = function(self)
|
core.suspend = function(self)
|
||||||
self.suspending = true
|
self.suspending = true
|
||||||
return function()
|
-- It's needed to avoid conflicting with autocmd debouncing.
|
||||||
|
return vim.schedule_wrap(function()
|
||||||
self.suspending = false
|
self.suspending = false
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Get sources that sorted by priority
|
---Get sources that sorted by priority
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ cmp.setup = setmetatable({
|
|||||||
-- In InsertEnter autocmd, vim will detects mode=normal unexpectedly.
|
-- In InsertEnter autocmd, vim will detects mode=normal unexpectedly.
|
||||||
autocmd.subscribe(
|
autocmd.subscribe(
|
||||||
{ 'InsertEnter', 'CmdlineEnter' },
|
{ 'InsertEnter', 'CmdlineEnter' },
|
||||||
async.debounce_safe_state(function()
|
async.debounce_next_tick(function()
|
||||||
if config.enabled() then
|
if config.enabled() then
|
||||||
cmp.config.compare.scopes:update()
|
cmp.config.compare.scopes:update()
|
||||||
cmp.config.compare.locality:update()
|
cmp.config.compare.locality:update()
|
||||||
@@ -300,31 +300,31 @@ autocmd.subscribe(
|
|||||||
-- async.throttle is needed for performance. The mapping `:<C-u>...<CR>` will fire `CmdlineChanged` for each character.
|
-- async.throttle is needed for performance. The mapping `:<C-u>...<CR>` will fire `CmdlineChanged` for each character.
|
||||||
autocmd.subscribe(
|
autocmd.subscribe(
|
||||||
{ 'TextChangedI', 'TextChangedP', 'CmdlineChanged' },
|
{ 'TextChangedI', 'TextChangedP', 'CmdlineChanged' },
|
||||||
async.debounce_safe_state(function()
|
async.debounce_next_tick(function()
|
||||||
if config.enabled() then
|
if config.enabled() then
|
||||||
cmp.core:on_change('TextChanged')
|
cmp.core:on_change('TextChanged')
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
autocmd.subscribe(
|
||||||
|
'CursorMovedI',
|
||||||
|
async.debounce_next_tick(function()
|
||||||
|
if config.enabled() then
|
||||||
|
cmp.core:on_moved()
|
||||||
|
else
|
||||||
|
cmp.core:reset()
|
||||||
|
cmp.core.view:close()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
)
|
||||||
|
|
||||||
-- If make this asynchronous, the completion menu will not close when the command output is displayed.
|
-- If make this asynchronous, the completion menu will not close when the command output is displayed.
|
||||||
autocmd.subscribe({ 'InsertLeave', 'CmdlineLeave' }, function()
|
autocmd.subscribe({ 'InsertLeave', 'CmdlineLeave' }, function()
|
||||||
cmp.core:reset()
|
cmp.core:reset()
|
||||||
cmp.core.view:close()
|
cmp.core.view:close()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
autocmd.subscribe(
|
|
||||||
'CursorMovedI',
|
|
||||||
async.debounce_safe_state(function()
|
|
||||||
if config.enabled() then
|
|
||||||
cmp.core:on_moved()
|
|
||||||
else
|
|
||||||
cmp.core:reset()
|
|
||||||
cmp.core.view:close()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
)
|
|
||||||
|
|
||||||
cmp.event:on('complete_done', function(evt)
|
cmp.event:on('complete_done', function(evt)
|
||||||
if evt.entry then
|
if evt.entry then
|
||||||
cmp.config.compare.recently_used:add_entry(evt.entry)
|
cmp.config.compare.recently_used:add_entry(evt.entry)
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
local feedkeys = require('cmp.utils.feedkeys')
|
|
||||||
|
|
||||||
local async = {}
|
local async = {}
|
||||||
|
|
||||||
---@class cmp.AsyncThrottle
|
---@class cmp.AsyncThrottle
|
||||||
@@ -112,14 +110,14 @@ async.sync = function(runner, timeout)
|
|||||||
end
|
end
|
||||||
|
|
||||||
---Wait and callback for next safe state.
|
---Wait and callback for next safe state.
|
||||||
async.debounce_safe_state = function(callback)
|
async.debounce_next_tick = function(callback)
|
||||||
local running = false
|
local running = false
|
||||||
return function()
|
return function()
|
||||||
if running then
|
if running then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
running = true
|
running = true
|
||||||
feedkeys.call('', 'n', function()
|
vim.schedule(function()
|
||||||
running = false
|
running = false
|
||||||
callback()
|
callback()
|
||||||
end)
|
end)
|
||||||
|
|||||||
Reference in New Issue
Block a user