Decrease waits

This commit is contained in:
hrsh7th
2022-07-24 13:14:01 +09:00
parent bf5593df8e
commit 76ba56ce96
6 changed files with 18 additions and 11 deletions

View File

@@ -383,6 +383,12 @@ performance.throttle~
Sets throttle time Sets throttle time
This is used to delay filtering and displaying completions. 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* *cmp-config.preselect*
preselect~ preselect~
`cmp.PreselectMode` `cmp.PreselectMode`

View File

@@ -15,8 +15,9 @@ return function()
end, end,
performance = { performance = {
debounce = 80, debounce = 60,
throttle = 40, throttle = 30,
fetching_timeout = 200,
}, },
preselect = types.cmp.PreselectMode.Item, preselect = types.cmp.PreselectMode.Item,

View File

@@ -14,8 +14,6 @@ local types = require('cmp.types')
local api = require('cmp.utils.api') local api = require('cmp.utils.api')
local event = require('cmp.utils.event') local event = require('cmp.utils.event')
local SOURCE_TIMEOUT = 500
---@class cmp.Core ---@class cmp.Core
---@field public suspending boolean ---@field public suspending boolean
---@field public view cmp.View ---@field public view cmp.View
@@ -55,7 +53,7 @@ core.unregister_source = function(self, source_id)
end end
---Get new context ---Get new context
---@param option cmp.ContextOption ---@param option? cmp.ContextOption
---@return cmp.Context ---@return cmp.Context
core.get_context = function(self, option) core.get_context = function(self, option)
local prev = self.context:clone() local prev = self.context:clone()
@@ -81,7 +79,7 @@ core.suspend = function(self)
end end
---Get sources that sorted by priority ---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[] ---@return cmp.Source[]
core.get_sources = function(self, filter) core.get_sources = function(self, filter)
local f = function(s) local f = function(s)
@@ -241,7 +239,7 @@ core.complete_common_string = function(self)
config.set_onetime({}) config.set_onetime({})
local cursor = api.get_cursor() local cursor = api.get_cursor()
local offset = self.view:get_offset() local offset = self.view:get_offset() or cursor[2]
local common_string local common_string
for _, e in ipairs(self.view:get_entries()) do for _, e in ipairs(self.view:get_entries()) do
local vim_item = e:get_vim_item(offset) local vim_item = e:get_vim_item(offset)
@@ -309,8 +307,8 @@ core.filter = async.throttle(function(self)
local sources = {} local sources = {}
for _, s in ipairs(self:get_sources({ source.SourceStatus.FETCHING, source.SourceStatus.COMPLETED })) do for _, s in ipairs(self:get_sources({ source.SourceStatus.FETCHING, source.SourceStatus.COMPLETED })) do
-- Reserve filter call for timeout. -- Reserve filter call for timeout.
if not s.incomplete and SOURCE_TIMEOUT > s:get_fetching_time() then if not s.incomplete and config.get().performance.fetching_timeout > s:get_fetching_time() then
self.filter.timeout = SOURCE_TIMEOUT - s:get_fetching_time() self.filter.timeout = config.get().performance.fetching_timeout - s:get_fetching_time()
self:filter() self:filter()
if #sources == 0 then if #sources == 0 then
return return

View File

@@ -97,6 +97,7 @@ cmp.ItemField = {
---@class cmp.PerformanceConfig ---@class cmp.PerformanceConfig
---@field public debounce integer ---@field public debounce integer
---@field public throttle integer ---@field public throttle integer
---@field public fetching_timeout integer
---@class cmp.WindowConfig ---@class cmp.WindowConfig
---@field completion cmp.WindowConfig ---@field completion cmp.WindowConfig

View File

@@ -44,6 +44,7 @@ api.get_current_line = function()
return vim.api.nvim_get_current_line() return vim.api.nvim_get_current_line()
end end
---@return { [1]: integer, [2]: integer }
api.get_cursor = function() api.get_cursor = function()
if api.is_cmdline_mode() then if api.is_cmdline_mode() then
return { vim.o.lines - (vim.api.nvim_get_option('cmdheight') or 1) + 1, vim.fn.getcmdpos() - 1 } return { vim.o.lines - (vim.api.nvim_get_option('cmdheight') or 1) + 1, vim.fn.getcmdpos() - 1 }

View File

@@ -68,7 +68,7 @@ keymap.undojoin = function()
end end
---Create backspace keys. ---Create backspace keys.
---@param count integer ---@param count string|integer
---@return string ---@return string
keymap.backspace = function(count) keymap.backspace = function(count)
if type(count) == 'string' then if type(count) == 'string' then
@@ -83,7 +83,7 @@ keymap.backspace = function(count)
end end
---Update indentkeys. ---Update indentkeys.
---@param expr string ---@param expr? string
---@return string ---@return string
keymap.indentkeys = function(expr) keymap.indentkeys = function(expr)
return string.format(keymap.t('<Cmd>set indentkeys=%s<CR>'), expr and vim.fn.escape(expr, '| \t\\') or '') return string.format(keymap.t('<Cmd>set indentkeys=%s<CR>'), expr and vim.fn.escape(expr, '| \t\\') or '')