chore(mapping): add support for toggling suggestion (#546)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
@@ -32,7 +32,6 @@ function Suggestion:new(id)
|
||||
local o = { id = id, suggestions = {} }
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
self.augroup = api.nvim_create_augroup("avante_suggestion_" .. id, { clear = true })
|
||||
self.extmark_id = 1
|
||||
self._timer = nil
|
||||
self._contexts = {}
|
||||
@@ -41,7 +40,6 @@ function Suggestion:new(id)
|
||||
api.nvim_exec_autocmds("User", { pattern = Provider.env.REQUEST_LOGIN_PATTERN })
|
||||
vim.g.avante_login = true
|
||||
end
|
||||
self:setup_mappings()
|
||||
self:setup_autocmds()
|
||||
end
|
||||
return o
|
||||
@@ -51,44 +49,6 @@ function Suggestion:destroy()
|
||||
self:stop_timer()
|
||||
self:reset()
|
||||
self:delete_autocmds()
|
||||
api.nvim_del_namespace(SUGGESTION_NS)
|
||||
end
|
||||
|
||||
function Suggestion:setup_mappings()
|
||||
if not Config.behaviour.auto_set_keymaps then return end
|
||||
if Config.mappings.suggestion and Config.mappings.suggestion.accept then
|
||||
vim.keymap.set("i", Config.mappings.suggestion.accept, function() self:accept() end, {
|
||||
desc = "[avante] accept suggestion",
|
||||
noremap = true,
|
||||
silent = true,
|
||||
})
|
||||
end
|
||||
|
||||
if Config.mappings.suggestion and Config.mappings.suggestion.dismiss then
|
||||
vim.keymap.set("i", Config.mappings.suggestion.dismiss, function()
|
||||
if self:is_visible() then self:dismiss() end
|
||||
end, {
|
||||
desc = "[avante] dismiss suggestion",
|
||||
noremap = true,
|
||||
silent = true,
|
||||
})
|
||||
end
|
||||
|
||||
if Config.mappings.suggestion and Config.mappings.suggestion.next then
|
||||
vim.keymap.set("i", Config.mappings.suggestion.next, function() self:next() end, {
|
||||
desc = "[avante] next suggestion",
|
||||
noremap = true,
|
||||
silent = true,
|
||||
})
|
||||
end
|
||||
|
||||
if Config.mappings.suggestion and Config.mappings.suggestion.prev then
|
||||
vim.keymap.set("i", Config.mappings.suggestion.prev, function() self:prev() end, {
|
||||
desc = "[avante] previous suggestion",
|
||||
noremap = true,
|
||||
silent = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
function Suggestion:suggest()
|
||||
@@ -307,6 +267,7 @@ function Suggestion:accept()
|
||||
end
|
||||
|
||||
function Suggestion:setup_autocmds()
|
||||
self.augroup = api.nvim_create_augroup("avante_suggestion_" .. self.id, { clear = true })
|
||||
local last_cursor_pos = {}
|
||||
|
||||
local check_for_suggestion = Utils.debounce(function()
|
||||
|
||||
Reference in New Issue
Block a user