make debounce and throttle time configurable (#1026)
* make debounce and throttle time configurable * fix documentation
This commit is contained in:
13
doc/cmp.txt
13
doc/cmp.txt
@@ -366,6 +366,19 @@ enabled~
|
|||||||
`boolean | fun(): boolean`
|
`boolean | fun(): boolean`
|
||||||
Toggles the plugin on and off.
|
Toggles the plugin on and off.
|
||||||
|
|
||||||
|
*cmp-config.performance.debounce*
|
||||||
|
performance.debounce~
|
||||||
|
`number`
|
||||||
|
Sets debounce time
|
||||||
|
This is the interval used to group up completions from different sources
|
||||||
|
for filtering and displaying.
|
||||||
|
|
||||||
|
*cmp-config.performance.throttle*
|
||||||
|
performance.throttle~
|
||||||
|
`number`
|
||||||
|
Sets throttle time
|
||||||
|
This is used to delay filtering and displaying completions.
|
||||||
|
|
||||||
*cmp-config.preselect*
|
*cmp-config.preselect*
|
||||||
preselect~
|
preselect~
|
||||||
`cmp.PreselectMode`
|
`cmp.PreselectMode`
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ return function()
|
|||||||
return not disabled
|
return not disabled
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
performance = {
|
||||||
|
debounce = 80,
|
||||||
|
throttle = 40,
|
||||||
|
},
|
||||||
|
|
||||||
preselect = types.cmp.PreselectMode.Item,
|
preselect = types.cmp.PreselectMode.Item,
|
||||||
|
|
||||||
mapping = {},
|
mapping = {},
|
||||||
|
|||||||
@@ -15,8 +15,6 @@ local api = require('cmp.utils.api')
|
|||||||
local event = require('cmp.utils.event')
|
local event = require('cmp.utils.event')
|
||||||
|
|
||||||
local SOURCE_TIMEOUT = 500
|
local SOURCE_TIMEOUT = 500
|
||||||
local DEBOUNCE_TIME = 80
|
|
||||||
local THROTTLE_TIME = 40
|
|
||||||
|
|
||||||
---@class cmp.Core
|
---@class cmp.Core
|
||||||
---@field public suspending boolean
|
---@field public suspending boolean
|
||||||
@@ -169,7 +167,7 @@ core.on_change = function(self, trigger_event)
|
|||||||
if vim.tbl_contains(config.get().completion.autocomplete or {}, trigger_event) then
|
if vim.tbl_contains(config.get().completion.autocomplete or {}, trigger_event) then
|
||||||
self:complete(ctx)
|
self:complete(ctx)
|
||||||
else
|
else
|
||||||
self.filter.timeout = self.view:visible() and THROTTLE_TIME or 0
|
self.filter.timeout = self.view:visible() and config.get().performance.throttle or 0
|
||||||
self:filter()
|
self:filter()
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -279,7 +277,7 @@ core.complete = function(self, ctx)
|
|||||||
else
|
else
|
||||||
if not self.view:get_active_entry() then
|
if not self.view:get_active_entry() then
|
||||||
self.filter.stop()
|
self.filter.stop()
|
||||||
self.filter.timeout = DEBOUNCE_TIME
|
self.filter.timeout = config.get().performance.debounce
|
||||||
self:filter()
|
self:filter()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -289,14 +287,14 @@ core.complete = function(self, ctx)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not self.view:get_active_entry() then
|
if not self.view:get_active_entry() then
|
||||||
self.filter.timeout = self.view:visible() and THROTTLE_TIME or 1
|
self.filter.timeout = self.view:visible() and config.get().performance.throttle or 1
|
||||||
self:filter()
|
self:filter()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---Update completion menu
|
---Update completion menu
|
||||||
core.filter = async.throttle(function(self)
|
core.filter = async.throttle(function(self)
|
||||||
self.filter.timeout = THROTTLE_TIME
|
self.filter.timeout = config.get().performance.throttle
|
||||||
|
|
||||||
-- Check invalid condition.
|
-- Check invalid condition.
|
||||||
local ignore = false
|
local ignore = false
|
||||||
@@ -335,7 +333,7 @@ core.filter = async.throttle(function(self)
|
|||||||
end) == 0 then
|
end) == 0 then
|
||||||
config.set_onetime({})
|
config.set_onetime({})
|
||||||
end
|
end
|
||||||
end, THROTTLE_TIME)
|
end, config.get().performance.throttle)
|
||||||
|
|
||||||
---Confirm completion.
|
---Confirm completion.
|
||||||
---@param e cmp.Entry
|
---@param e cmp.Entry
|
||||||
|
|||||||
@@ -80,6 +80,7 @@ cmp.ItemField = {
|
|||||||
---@class cmp.ConfigSchema
|
---@class cmp.ConfigSchema
|
||||||
---@field private revision number
|
---@field private revision number
|
||||||
---@field public enabled fun():boolean|boolean
|
---@field public enabled fun():boolean|boolean
|
||||||
|
---@field public performance cmp.PerformanceConfig
|
||||||
---@field public preselect cmp.PreselectMode
|
---@field public preselect cmp.PreselectMode
|
||||||
---@field public completion cmp.CompletionConfig
|
---@field public completion cmp.CompletionConfig
|
||||||
---@field public window cmp.WindowConfig|nil
|
---@field public window cmp.WindowConfig|nil
|
||||||
@@ -93,6 +94,10 @@ cmp.ItemField = {
|
|||||||
---@field public view cmp.ViewConfig
|
---@field public view cmp.ViewConfig
|
||||||
---@field public experimental cmp.ExperimentalConfig
|
---@field public experimental cmp.ExperimentalConfig
|
||||||
|
|
||||||
|
---@class cmp.PerformanceConfig
|
||||||
|
---@field public debounce number
|
||||||
|
---@field public throttle number
|
||||||
|
|
||||||
---@class cmp.WindowConfig
|
---@class cmp.WindowConfig
|
||||||
---@field completion cmp.WindowConfig
|
---@field completion cmp.WindowConfig
|
||||||
---@field documentation cmp.WindowConfig|nil
|
---@field documentation cmp.WindowConfig|nil
|
||||||
|
|||||||
Reference in New Issue
Block a user