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 <fanlizhou@yunqilaohe.com>
This commit is contained in:
doodleEsc 2024-09-27 20:27:24 +08:00 committed by GitHub
parent f3ee77dd5b
commit e5dc837715
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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