make debounce and throttle time configurable (#1026)

* make debounce and throttle time configurable

* fix documentation
This commit is contained in:
MurdeRM3L0DY
2022-06-14 19:21:55 +02:00
committed by GitHub
parent 15c7bf7c0d
commit 0e65333c7f
4 changed files with 28 additions and 7 deletions

View File

@@ -366,6 +366,19 @@ enabled~
`boolean | fun(): boolean`
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*
preselect~
`cmp.PreselectMode`

View File

@@ -14,6 +14,11 @@ return function()
return not disabled
end,
performance = {
debounce = 80,
throttle = 40,
},
preselect = types.cmp.PreselectMode.Item,
mapping = {},

View File

@@ -15,8 +15,6 @@ local api = require('cmp.utils.api')
local event = require('cmp.utils.event')
local SOURCE_TIMEOUT = 500
local DEBOUNCE_TIME = 80
local THROTTLE_TIME = 40
---@class cmp.Core
---@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
self:complete(ctx)
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()
end
else
@@ -279,7 +277,7 @@ core.complete = function(self, ctx)
else
if not self.view:get_active_entry() then
self.filter.stop()
self.filter.timeout = DEBOUNCE_TIME
self.filter.timeout = config.get().performance.debounce
self:filter()
end
end
@@ -289,14 +287,14 @@ core.complete = function(self, ctx)
end
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()
end
end
---Update completion menu
core.filter = async.throttle(function(self)
self.filter.timeout = THROTTLE_TIME
self.filter.timeout = config.get().performance.throttle
-- Check invalid condition.
local ignore = false
@@ -335,7 +333,7 @@ core.filter = async.throttle(function(self)
end) == 0 then
config.set_onetime({})
end
end, THROTTLE_TIME)
end, config.get().performance.throttle)
---Confirm completion.
---@param e cmp.Entry

View File

@@ -80,6 +80,7 @@ cmp.ItemField = {
---@class cmp.ConfigSchema
---@field private revision number
---@field public enabled fun():boolean|boolean
---@field public performance cmp.PerformanceConfig
---@field public preselect cmp.PreselectMode
---@field public completion cmp.CompletionConfig
---@field public window cmp.WindowConfig|nil
@@ -93,6 +94,10 @@ cmp.ItemField = {
---@field public view cmp.ViewConfig
---@field public experimental cmp.ExperimentalConfig
---@class cmp.PerformanceConfig
---@field public debounce number
---@field public throttle number
---@class cmp.WindowConfig
---@field completion cmp.WindowConfig
---@field documentation cmp.WindowConfig|nil