diff --git a/doc/cmp.txt b/doc/cmp.txt index 85207d2..274b48a 100644 --- a/doc/cmp.txt +++ b/doc/cmp.txt @@ -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` diff --git a/lua/cmp/config/default.lua b/lua/cmp/config/default.lua index dce5168..8327980 100644 --- a/lua/cmp/config/default.lua +++ b/lua/cmp/config/default.lua @@ -14,6 +14,11 @@ return function() return not disabled end, + performance = { + debounce = 80, + throttle = 40, + }, + preselect = types.cmp.PreselectMode.Item, mapping = {}, diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index 08949a9..81638b6 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -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 diff --git a/lua/cmp/types/cmp.lua b/lua/cmp/types/cmp.lua index 8759aca..b862b6b 100644 --- a/lua/cmp/types/cmp.lua +++ b/lua/cmp/types/cmp.lua @@ -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