Decrease waits
This commit is contained in:
@@ -383,6 +383,12 @@ performance.throttle~
|
||||
Sets throttle time
|
||||
This is used to delay filtering and displaying completions.
|
||||
|
||||
*cmp-config.performance.fetching_timeout*
|
||||
performance.fetching_timeout~
|
||||
`number`
|
||||
Sets the timeout of candidate fetching process.
|
||||
The nvim-cmp will wait to display the most prioritized source.
|
||||
|
||||
*cmp-config.preselect*
|
||||
preselect~
|
||||
`cmp.PreselectMode`
|
||||
|
||||
@@ -15,8 +15,9 @@ return function()
|
||||
end,
|
||||
|
||||
performance = {
|
||||
debounce = 80,
|
||||
throttle = 40,
|
||||
debounce = 60,
|
||||
throttle = 30,
|
||||
fetching_timeout = 200,
|
||||
},
|
||||
|
||||
preselect = types.cmp.PreselectMode.Item,
|
||||
|
||||
@@ -14,8 +14,6 @@ local types = require('cmp.types')
|
||||
local api = require('cmp.utils.api')
|
||||
local event = require('cmp.utils.event')
|
||||
|
||||
local SOURCE_TIMEOUT = 500
|
||||
|
||||
---@class cmp.Core
|
||||
---@field public suspending boolean
|
||||
---@field public view cmp.View
|
||||
@@ -55,7 +53,7 @@ core.unregister_source = function(self, source_id)
|
||||
end
|
||||
|
||||
---Get new context
|
||||
---@param option cmp.ContextOption
|
||||
---@param option? cmp.ContextOption
|
||||
---@return cmp.Context
|
||||
core.get_context = function(self, option)
|
||||
local prev = self.context:clone()
|
||||
@@ -81,7 +79,7 @@ core.suspend = function(self)
|
||||
end
|
||||
|
||||
---Get sources that sorted by priority
|
||||
---@param filter cmp.SourceStatus[]|fun(s: cmp.Source): boolean
|
||||
---@param filter? cmp.SourceStatus[]|fun(s: cmp.Source): boolean
|
||||
---@return cmp.Source[]
|
||||
core.get_sources = function(self, filter)
|
||||
local f = function(s)
|
||||
@@ -241,7 +239,7 @@ core.complete_common_string = function(self)
|
||||
config.set_onetime({})
|
||||
|
||||
local cursor = api.get_cursor()
|
||||
local offset = self.view:get_offset()
|
||||
local offset = self.view:get_offset() or cursor[2]
|
||||
local common_string
|
||||
for _, e in ipairs(self.view:get_entries()) do
|
||||
local vim_item = e:get_vim_item(offset)
|
||||
@@ -309,8 +307,8 @@ core.filter = async.throttle(function(self)
|
||||
local sources = {}
|
||||
for _, s in ipairs(self:get_sources({ source.SourceStatus.FETCHING, source.SourceStatus.COMPLETED })) do
|
||||
-- Reserve filter call for timeout.
|
||||
if not s.incomplete and SOURCE_TIMEOUT > s:get_fetching_time() then
|
||||
self.filter.timeout = SOURCE_TIMEOUT - s:get_fetching_time()
|
||||
if not s.incomplete and config.get().performance.fetching_timeout > s:get_fetching_time() then
|
||||
self.filter.timeout = config.get().performance.fetching_timeout - s:get_fetching_time()
|
||||
self:filter()
|
||||
if #sources == 0 then
|
||||
return
|
||||
|
||||
@@ -97,6 +97,7 @@ cmp.ItemField = {
|
||||
---@class cmp.PerformanceConfig
|
||||
---@field public debounce integer
|
||||
---@field public throttle integer
|
||||
---@field public fetching_timeout integer
|
||||
|
||||
---@class cmp.WindowConfig
|
||||
---@field completion cmp.WindowConfig
|
||||
|
||||
@@ -44,6 +44,7 @@ api.get_current_line = function()
|
||||
return vim.api.nvim_get_current_line()
|
||||
end
|
||||
|
||||
---@return { [1]: integer, [2]: integer }
|
||||
api.get_cursor = function()
|
||||
if api.is_cmdline_mode() then
|
||||
return { vim.o.lines - (vim.api.nvim_get_option('cmdheight') or 1) + 1, vim.fn.getcmdpos() - 1 }
|
||||
|
||||
@@ -68,7 +68,7 @@ keymap.undojoin = function()
|
||||
end
|
||||
|
||||
---Create backspace keys.
|
||||
---@param count integer
|
||||
---@param count string|integer
|
||||
---@return string
|
||||
keymap.backspace = function(count)
|
||||
if type(count) == 'string' then
|
||||
@@ -83,7 +83,7 @@ keymap.backspace = function(count)
|
||||
end
|
||||
|
||||
---Update indentkeys.
|
||||
---@param expr string
|
||||
---@param expr? string
|
||||
---@return string
|
||||
keymap.indentkeys = function(expr)
|
||||
return string.format(keymap.t('<Cmd>set indentkeys=%s<CR>'), expr and vim.fn.escape(expr, '| \t\\') or '')
|
||||
|
||||
Reference in New Issue
Block a user