From 97a639a060985be0be26d3eba828dd184d811b0f Mon Sep 17 00:00:00 2001 From: hrsh7th Date: Sat, 18 Sep 2021 00:29:34 +0900 Subject: [PATCH] Fix #217 --- lua/cmp/context.lua | 6 ++++++ lua/cmp/core.lua | 7 +++++++ 2 files changed, 13 insertions(+) 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 = {}