diff --git a/lua/cmp/context.lua b/lua/cmp/context.lua index c7de4e5..9eaa7d6 100644 --- a/lua/cmp/context.lua +++ b/lua/cmp/context.lua @@ -65,6 +65,12 @@ context.new = function(prev_context, option) return self end +---Return the context is invalid or not. +---@return boolean +context.invalid = function(self) + return string.sub(self.mode, 1, 1) ~= 'i' +end + ---Return context creation reason. ---@return cmp.ContextReason context.get_reason = function(self) diff --git a/lua/cmp/core.lua b/lua/cmp/core.lua index 9f71e76..bc96d5e 100644 --- a/lua/cmp/core.lua +++ b/lua/cmp/core.lua @@ -243,6 +243,10 @@ end ---Invoke completion ---@param ctx cmp.Context core.complete = function(ctx) + if ctx:invalid() then + return + end + core.set_context(ctx) local callback = function() @@ -265,6 +269,9 @@ end ---Update completion menu core.filter = async.throttle(function() local ctx = core.get_context() + if ctx:invalid() then + return + end -- To wait for processing source for that's timeout. local sources = {}