feat(api): support native chat mode (#541)

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham
2024-09-05 02:43:31 -04:00
committed by GitHub
parent a8ef7de7d8
commit 29e109e447
7 changed files with 45 additions and 23 deletions

View File

@@ -36,16 +36,25 @@ H.commands = function()
---@type AskOptions
local args = { question = nil, win = {} }
local q_parts = {}
local q_ask = nil
for _, arg in ipairs(opts.fargs) do
local value = arg:match("position=(%w+)")
if value then
local ask = arg:match("ask=(%w+)")
if ask ~= nil then
q_ask = ask == "true"
elseif 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)
require("avante.api").ask(
vim.tbl_deep_extend(
"force",
args,
{ ask = q_ask, question = #q_parts > 0 and table.concat(q_parts, " ") or nil }
)
)
end, {
desc = "avante: ask AI for code suggestions",
nargs = "*",
@@ -56,6 +65,7 @@ H.commands = function()
---@param x string
vim.tbl_map(function(x) return "position=" .. x end, { "left", "right", "top", "bottom" })
)
vim.list_extend(candidates, vim.tbl_map(function(x) return "ask=" .. x end, { "true", "false" }))
return candidates
end,
})
@@ -283,6 +293,8 @@ M.toggle = { api = true }
---@param opts? AskOptions
M.toggle_sidebar = function(opts)
opts = opts or {}
if opts.ask == nil then opts.ask = true end
local sidebar = M.get()
if not sidebar then
M._init(api.nvim_get_current_tabpage())