make debounce and throttle time configurable (#1026)
* make debounce and throttle time configurable * fix documentation
This commit is contained in:
@@ -14,6 +14,11 @@ return function()
|
||||
return not disabled
|
||||
end,
|
||||
|
||||
performance = {
|
||||
debounce = 80,
|
||||
throttle = 40,
|
||||
},
|
||||
|
||||
preselect = types.cmp.PreselectMode.Item,
|
||||
|
||||
mapping = {},
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user