diff --git a/doc/cmp.txt b/doc/cmp.txt index bfd7f37..d237c75 100644 --- a/doc/cmp.txt +++ b/doc/cmp.txt @@ -440,6 +440,11 @@ performance.fetching_timeout~ Sets the timeout of candidate fetching process. The nvim-cmp will wait to display the most prioritized source. + *cmp-config.performance.confirm_resolve_timeout* +performance.confirm_resolve_timeout~ + `number` + Sets the timeout for resolving item before confirmation. + *cmp-config.performance.async_budget* performance.async_budget~ `number` diff --git a/lua/cmp/config/default.lua b/lua/cmp/config/default.lua index 02296c9..c2bdcec 100644 --- a/lua/cmp/config/default.lua +++ b/lua/cmp/config/default.lua @@ -19,6 +19,7 @@ return function() debounce = 60, throttle = 30, fetching_timeout = 500, + confirm_resolve_timeout = 80, async_budget = 1, max_view_entries = 200, }, diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index b4243ec..bdfe7b4 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -1,7 +1,6 @@ local debug = require('cmp.utils.debug') local str = require('cmp.utils.str') local char = require('cmp.utils.char') -local pattern = require('cmp.utils.pattern') local feedkeys = require('cmp.utils.feedkeys') local async = require('cmp.utils.async') local keymap = require('cmp.utils.keymap') @@ -363,6 +362,10 @@ core.confirm = function(self, e, option, callback) debug.log('entry.confirm', e:get_completion_item()) + async.sync(function(done) + e:resolve(done) + end, config.get().performance.confirm_resolve_timeout) + local release = self:suspend() -- Close menus. diff --git a/lua/cmp/source.lua b/lua/cmp/source.lua index d57b355..b48bdec 100644 --- a/lua/cmp/source.lua +++ b/lua/cmp/source.lua @@ -57,7 +57,8 @@ source.reset = function(self) self.request_offset = -1 self.completion_context = nil self.status = source.SourceStatus.WAITING - self.complete_dedup(function() end) + self.complete_dedup(function() + end) end ---Return source config @@ -90,12 +91,14 @@ source.get_entries = function(self, ctx) local target_entries = self.entries - local prev = self.cache:get({ 'get_entries', tostring(self.revision) }) - if prev and ctx.cursor.row == prev.ctx.cursor.row and self.offset == prev.offset then - -- only use prev entries when cursor is moved forward. - -- and the pattern offset is the same. - if prev.ctx.cursor.col <= ctx.cursor.col then - target_entries = prev.entries + if not self.incomplete then + local prev = self.cache:get({ 'get_entries', tostring(self.revision) }) + if prev and ctx.cursor.row == prev.ctx.cursor.row and self.offset == prev.offset then + -- only use prev entries when cursor is moved forward. + -- and the pattern offset is the same. + if prev.ctx.cursor.col <= ctx.cursor.col then + target_entries = prev.entries + end end end @@ -128,7 +131,9 @@ source.get_entries = function(self, ctx) end end - self.cache:set({ 'get_entries', tostring(self.revision) }, { entries = entries, ctx = ctx, offset = self.offset }) + if not self.incomplete then + self.cache:set({ 'get_entries', tostring(self.revision) }, { entries = entries, ctx = ctx, offset = self.offset }) + end if self:get_source_config().max_item_count then local limited_entries = {} diff --git a/lua/cmp/types/cmp.lua b/lua/cmp/types/cmp.lua index 0c347f4..cddbcdc 100644 --- a/lua/cmp/types/cmp.lua +++ b/lua/cmp/types/cmp.lua @@ -103,6 +103,7 @@ cmp.ItemField = { ---@field public debounce integer ---@field public throttle integer ---@field public fetching_timeout integer +---@field public confirm_resolve_timeout integer ---@field public async_budget integer Maximum time (in ms) an async function is allowed to run during one step of the event loop. ---@field public max_view_entries integer