feat(api): support for ask customization (#527)
Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
@@ -32,11 +32,33 @@ H.commands = function()
|
||||
api.nvim_create_user_command("Avante" .. n, c, o)
|
||||
end
|
||||
|
||||
cmd(
|
||||
"Ask",
|
||||
function(opts) require("avante.api").ask(vim.trim(opts.args)) end,
|
||||
{ desc = "avante: ask AI for code suggestions", nargs = "*" }
|
||||
)
|
||||
cmd("Ask", function(opts)
|
||||
---@type AskOptions
|
||||
local args = { question = nil, win = {} }
|
||||
local q_parts = {}
|
||||
for _, arg in ipairs(opts.fargs) do
|
||||
local value = arg:match("position=(%w+)")
|
||||
if value then
|
||||
args.win.position = value
|
||||
else
|
||||
table.insert(q_parts, arg)
|
||||
end
|
||||
end
|
||||
args.question = #q_parts > 0 and table.concat(q_parts, " ") or nil
|
||||
require("avante.api").ask(args)
|
||||
end, {
|
||||
desc = "avante: ask AI for code suggestions",
|
||||
nargs = "*",
|
||||
complete = function(_, _, _)
|
||||
local candidates = {} ---@type string[]
|
||||
vim.list_extend(
|
||||
candidates,
|
||||
---@param x string
|
||||
vim.tbl_map(function(x) return "position=" .. x end, { "left", "right", "top", "bottom" })
|
||||
)
|
||||
return candidates
|
||||
end,
|
||||
})
|
||||
cmd("Toggle", function() M.toggle() end, { desc = "avante: toggle AI panel" })
|
||||
cmd(
|
||||
"Edit",
|
||||
@@ -258,6 +280,19 @@ end
|
||||
|
||||
M.toggle = { api = true }
|
||||
|
||||
---@param opts? AskOptions
|
||||
M.toggle_sidebar = function(opts)
|
||||
opts = opts or {}
|
||||
local sidebar = M.get()
|
||||
if not sidebar then
|
||||
M._init(api.nvim_get_current_tabpage())
|
||||
M.current.sidebar:open(opts)
|
||||
return true
|
||||
end
|
||||
|
||||
return sidebar:toggle(opts)
|
||||
end
|
||||
|
||||
M.toggle.debug = H.api(Utils.toggle_wrap({
|
||||
name = "debug",
|
||||
get = function() return Config.debug end,
|
||||
@@ -272,16 +307,7 @@ M.toggle.hint = H.api(Utils.toggle_wrap({
|
||||
|
||||
setmetatable(M.toggle, {
|
||||
__index = M.toggle,
|
||||
__call = function()
|
||||
local sidebar = M.get()
|
||||
if not sidebar then
|
||||
M._init(api.nvim_get_current_tabpage())
|
||||
M.current.sidebar:open()
|
||||
return true
|
||||
end
|
||||
|
||||
return sidebar:toggle()
|
||||
end,
|
||||
__call = function() M.toggle_sidebar() end,
|
||||
})
|
||||
|
||||
---@param opts? avante.Config
|
||||
|
||||
Reference in New Issue
Block a user