diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index 7d8a7f7..656e3f2 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -76,16 +76,10 @@ core.on_keymap = function(keys, fallback) if not e then return fallback() end - local pre = core.get_context() core.confirm(e, { behavior = c.behavior, }, function() - local new = core.get_context({ reason = types.cmp.ContextReason.TriggerOnly }) - if new:changed(pre) then - core.complete(new) - else - core.reset() - end + core.complete(core.get_context({ reason = types.cmp.ContextReason.TriggerOnly })) end) return end @@ -146,7 +140,7 @@ end ---Invoke completion ---@param ctx cmp.Context core.complete = function(ctx) - for _, s in ipairs(core.get_sources({ source.SourceStatus.WAITING, source.SourceStatus.COMPLETED })) do + for _, s in ipairs(core.get_sources()) do s:complete(ctx, function() local new = context.new(ctx) if new:changed(new.prev_context) then diff --git a/lua/cmp/float.lua b/lua/cmp/float.lua index 8124078..20efe1d 100644 --- a/lua/cmp/float.lua +++ b/lua/cmp/float.lua @@ -106,7 +106,7 @@ float.close = async.throttle( self.buf = nil self.win = nil end), - 0 + 20 ) return float diff --git a/lua/cmp/menu.lua b/lua/cmp/menu.lua index 0eeeca8..ad2018a 100644 --- a/lua/cmp/menu.lua +++ b/lua/cmp/menu.lua @@ -138,10 +138,6 @@ menu.update = function(self, ctx, sources) self.preselect = preselect self.context = ctx self:show() - - if #self.entries == 0 then - self:unselect() - end end ---Restore previous menu @@ -164,6 +160,7 @@ end ---Show completion item menu.show = function(self) if vim.fn.pumvisible() == 0 and #self.entries == 0 then + self:close() return end @@ -174,11 +171,10 @@ menu.show = function(self) vim.cmd('set completeopt=' .. config.get().completion.completeopt) end vim.fn.complete(self.offset, self.items) - vim.cmd('set completeopt=' .. completeopt) - if self.preselect > 0 then vim.api.nvim_select_popupmenu_item(self.preselect - 1, false, false, {}) end + vim.cmd('set completeopt=' .. completeopt) end ---Select current item diff --git a/lua/cmp/source.lua b/lua/cmp/source.lua index 4a4d78f..317b8e5 100644 --- a/lua/cmp/source.lua +++ b/lua/cmp/source.lua @@ -30,11 +30,6 @@ source.SourceStatus.WAITING = 1 source.SourceStatus.FETCHING = 2 source.SourceStatus.COMPLETED = 3 ----@alias cmp.SourceChangeKind "1" | "2" | "3" -source.SourceChangeKind = {} -source.SourceChangeKind.RETRIEVE = 1 -source.SourceChangeKind.CONTINUE = 2 - ---@return cmp.Source source.new = function(name, s) local self = setmetatable({}, { __index = source }) @@ -51,6 +46,7 @@ end ---Reset current completion state ---@return boolean source.reset = function(self) + debug.log(self.id, self.name, 'source.reset') self.cache:clear() self.revision = self.revision + 1 self.context = context.empty() @@ -242,6 +238,9 @@ source.complete = function(self, ctx, callback) end if not completion_context then debug.log('skip empty context', self.name, self.id) + if ctx:get_reason() == types.cmp.ContextReason.TriggerOnly then + self:reset() + end return end