From e5dc837715b21e32af621d7d6354937faea67992 Mon Sep 17 00:00:00 2001 From: doodleEsc <1056315827@qq.com> Date: Fri, 27 Sep 2024 20:27:24 +0800 Subject: [PATCH] fix: unregister completion source where BufLeave (#656) - Add an autocommand to unregister completion sources when leaving the buffer - Include a description for the new autocommand for better clarity Co-authored-by: fanlizhou --- lua/avante/sidebar.lua | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lua/avante/sidebar.lua b/lua/avante/sidebar.lua index 1524e6b..bf22371 100644 --- a/lua/avante/sidebar.lua +++ b/lua/avante/sidebar.lua @@ -1403,6 +1403,24 @@ function Sidebar:create_input(opts) end, }) + -- Unregister completion + api.nvim_create_autocmd("BufLeave", { + group = self.augroup, + buffer = self.input.bufnr, + once = false, + desc = "Unregister the completion of helpers in the input buffer", + callback = function() + local has_cmp, cmp = pcall(require, "cmp") + if has_cmp then + for _, source in ipairs(cmp.core:get_sources()) do + if source.name == "avante_commands" or source.name == "avante_mentions" then + cmp.unregister_source(source.id) + end + end + end + end, + }) + -- Close the floating window local function close_hint() if hint_window and api.nvim_win_is_valid(hint_window) then