Skip to content

Commit

Permalink
fix: unregister completion source where BufLeave (yetone#656)
Browse files Browse the repository at this point in the history
- 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>
  • Loading branch information
doodleEsc and fanlizhou authored Sep 27, 2024
1 parent f3ee77d commit e5dc837
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lua/avante/sidebar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5dc837

Please sign in to comment.