Compare commits
10 Commits
7daed04ff5
...
f7205c3e5a
Author | SHA1 | Date | |
---|---|---|---|
![]() |
f7205c3e5a | ||
![]() |
1ce3efbfe6 | ||
![]() |
c8460ca574 | ||
![]() |
2086f7d9bc | ||
![]() |
0e142811f4 | ||
![]() |
481bed92cd | ||
![]() |
3e94b5bd0c | ||
1be1c2bbbd | |||
545a8419a7 | |||
![]() |
79ded43408 |
@ -142,16 +142,7 @@ M._defaults = {
|
||||
temperature = 0,
|
||||
max_tokens = 8000,
|
||||
},
|
||||
---@type AvanteSupportedProvider
|
||||
["baidu"] = {
|
||||
__inherited_from = "openai",
|
||||
model = "deekseek-r1",
|
||||
timeout = 30000, -- Timeout in milliseconds
|
||||
temperature = 0,
|
||||
max_tokens = 8000,
|
||||
endpoint = "https://qianfan.baidubce.com/v2/chat/completions",
|
||||
appid = "app-QzGDePL0",
|
||||
},
|
||||
|
||||
---@type AvanteSupportedProvider
|
||||
["claude-opus"] = {
|
||||
__inherited_from = "claude",
|
||||
@ -265,8 +256,12 @@ M._defaults = {
|
||||
files = {
|
||||
add_current = "<leader>ac", -- Add current buffer to selected files
|
||||
},
|
||||
providers = {
|
||||
show_provides = "<leader>ap", -- Show providers selector
|
||||
},
|
||||
},
|
||||
windows = {
|
||||
|
||||
---@alias AvantePosition "right" | "left" | "top" | "bottom" | "smart"
|
||||
position = "right",
|
||||
wrap = true, -- similar to vim.o.wrap
|
||||
|
@ -68,6 +68,11 @@ H.keymaps = function()
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggleHint)", function() M.toggle.hint() end)
|
||||
vim.keymap.set("n", "<Plug>(AvanteToggleSuggestion)", function() M.toggle.suggestion() end)
|
||||
|
||||
vim.keymap.set("n", "<Plug>(AvanteShowProviders)", function()
|
||||
local sidebar = M.get()
|
||||
if sidebar then sidebar:show_providers_selector() end
|
||||
end)
|
||||
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictOurs)", function() Diff.choose("ours") end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictBoth)", function() Diff.choose("both") end)
|
||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictTheirs)", function() Diff.choose("theirs") end)
|
||||
@ -121,6 +126,14 @@ H.keymaps = function()
|
||||
function() M.toggle.suggestion() end,
|
||||
{ desc = "avante: toggle suggestion" }
|
||||
)
|
||||
Utils.safe_keymap_set("n", Config.mappings.show_providers, function()
|
||||
local sidebar = M.get()
|
||||
if sidebar then sidebar:show_providers_selector() end
|
||||
end, {
|
||||
desc = "avante: show providers selector",
|
||||
noremap = true,
|
||||
silent = true,
|
||||
})
|
||||
Utils.safe_keymap_set("n", Config.mappings.toggle.repomap, function() require("avante.repo_map").show() end, {
|
||||
desc = "avante: display repo map",
|
||||
noremap = true,
|
||||
|
@ -196,10 +196,6 @@ M.parse_messages = function(opts)
|
||||
end
|
||||
|
||||
M.parse_response = function(ctx, data_stream, _, opts)
|
||||
if data_stream:match('"%[DONE%]":') then
|
||||
opts.on_stop({ reason = "complete" })
|
||||
return
|
||||
end
|
||||
if data_stream:match('"delta":') then
|
||||
---@type OpenAIChatResponse
|
||||
local jsn = vim.json.decode(data_stream)
|
||||
@ -284,7 +280,13 @@ M.parse_curl_args = function(provider, prompt_opts)
|
||||
}
|
||||
|
||||
-- Add appid header for baidu provider
|
||||
if Config.provider == "baidu" then headers["appid"] = "app-QzGDePL0" end
|
||||
if Config.provider == "baidu" then
|
||||
local baidu_config = Config.get_provider("baidu")
|
||||
if not baidu_config.appid or baidu_config.appid == "" then
|
||||
error("Baidu provider requires 'appid' to be set in config")
|
||||
end
|
||||
headers["appid"] = baidu_config.appid
|
||||
end
|
||||
|
||||
if P.env.require_api_key(base) then
|
||||
local api_key = provider.parse_api_key()
|
||||
|
@ -1017,6 +1017,76 @@ function Sidebar:on_mount(opts)
|
||||
})
|
||||
end
|
||||
|
||||
-- Add keymap to add current buffer while sidebar is open
|
||||
if Config.mappings.providers and Config.mappings.providers.show_providers then
|
||||
vim.keymap.set("n", Config.mappings.providers.show_providers, function()
|
||||
local providers = require("avante.providers")
|
||||
local current_provider = Config.provider
|
||||
|
||||
-- Create a new buffer
|
||||
local bufnr = api.nvim_create_buf(false, true)
|
||||
|
||||
-- Set buffer content
|
||||
local lines = {}
|
||||
for provider, _ in pairs(providers) do
|
||||
if provider == current_provider then
|
||||
table.insert(lines, "> " .. provider .. " <")
|
||||
else
|
||||
table.insert(lines, " " .. provider)
|
||||
end
|
||||
end
|
||||
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
|
||||
-- Create a floating window
|
||||
local width = 40
|
||||
local height = #lines
|
||||
local win_opts = {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = height,
|
||||
col = (vim.o.columns - width) / 2,
|
||||
row = (vim.o.lines - height) / 2 - 1,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
}
|
||||
|
||||
local winid = api.nvim_open_win(bufnr, true, win_opts)
|
||||
|
||||
-- Highlight current provider
|
||||
api.nvim_buf_add_highlight(bufnr, -1, "AvanteProviderCurrent", 0, 0, -1)
|
||||
|
||||
-- Key mappings
|
||||
local function move_selection(direction)
|
||||
local cursor = api.nvim_win_get_cursor(winid)
|
||||
local line = cursor[1]
|
||||
|
||||
if direction == "up" and line > 1 then
|
||||
api.nvim_win_set_cursor(winid, { line - 1, 0 })
|
||||
elseif direction == "down" and line < #lines then
|
||||
api.nvim_win_set_cursor(winid, { line + 1, 0 })
|
||||
end
|
||||
end
|
||||
|
||||
local function select_provider()
|
||||
local cursor = api.nvim_win_get_cursor(winid)
|
||||
local line = cursor[1]
|
||||
local selected_provider = lines[line]:match("%S+$")
|
||||
|
||||
if selected_provider and selected_provider ~= current_provider then providers.refresh(selected_provider) end
|
||||
|
||||
api.nvim_win_close(winid, true)
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<Up>", function() move_selection("up") end, { buffer = bufnr })
|
||||
vim.keymap.set("n", "<Down>", function() move_selection("down") end, { buffer = bufnr })
|
||||
vim.keymap.set("n", "<CR>", select_provider, { buffer = bufnr })
|
||||
vim.keymap.set("n", "q", function() api.nvim_win_close(winid, true) end, { buffer = bufnr })
|
||||
end, {
|
||||
desc = "avante: show providers selector",
|
||||
noremap = true,
|
||||
silent = true,
|
||||
})
|
||||
end
|
||||
api.nvim_set_option_value("wrap", Config.windows.wrap, { win = self.result_container.winid })
|
||||
|
||||
local current_apply_extmark_id = nil
|
||||
@ -1219,6 +1289,12 @@ end
|
||||
--- Initialize the sidebar instance.
|
||||
--- @return avante.Sidebar The Sidebar instance.
|
||||
function Sidebar:initialize()
|
||||
-- Add keymap to show providers selector
|
||||
vim.keymap.set("n", "<leader>ap", function() self:show_providers_selector() end, { noremap = true, silent = true })
|
||||
|
||||
self.code.winid = api.nvim_get_current_win()
|
||||
self.code.bufnr = api.nvim_get_current_buf()
|
||||
self.code.selection = Utils.get_visual_selection_and_range()
|
||||
self.code.winid = api.nvim_get_current_win()
|
||||
self.code.bufnr = api.nvim_get_current_buf()
|
||||
self.code.selection = Utils.get_visual_selection_and_range()
|
||||
@ -2256,6 +2332,70 @@ function Sidebar:render(opts)
|
||||
return self
|
||||
end
|
||||
|
||||
function Sidebar:show_providers_selector()
|
||||
local providers = require("avante.providers")
|
||||
local current_provider = Config.provider
|
||||
|
||||
-- Create a new buffer
|
||||
local bufnr = api.nvim_create_buf(false, true)
|
||||
|
||||
-- Set buffer content
|
||||
local lines = {}
|
||||
for provider, _ in pairs(providers) do
|
||||
if provider == current_provider then
|
||||
table.insert(lines, "> " .. provider .. " <")
|
||||
else
|
||||
table.insert(lines, " " .. provider)
|
||||
end
|
||||
end
|
||||
api.nvim_buf_set_lines(bufnr, 0, -1, false, lines)
|
||||
|
||||
-- Create a floating window
|
||||
local width = 40
|
||||
local height = #lines
|
||||
local win_opts = {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = height,
|
||||
col = (vim.o.columns - width) / 2,
|
||||
row = (vim.o.lines - height) / 2 - 1,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
}
|
||||
|
||||
local winid = api.nvim_open_win(bufnr, true, win_opts)
|
||||
|
||||
-- Highlight current provider
|
||||
api.nvim_buf_add_highlight(bufnr, -1, "AvanteProviderCurrent", 0, 0, -1)
|
||||
|
||||
-- Key mappings
|
||||
local function move_selection(direction)
|
||||
local cursor = api.nvim_win_get_cursor(winid)
|
||||
local line = cursor[1]
|
||||
|
||||
if direction == "up" and line > 1 then
|
||||
api.nvim_win_set_cursor(winid, { line - 1, 0 })
|
||||
elseif direction == "down" and line < #lines then
|
||||
api.nvim_win_set_cursor(winid, { line + 1, 0 })
|
||||
end
|
||||
end
|
||||
|
||||
local function select_provider()
|
||||
local cursor = api.nvim_win_get_cursor(winid)
|
||||
local line = cursor[1]
|
||||
local selected_provider = lines[line]:match("%S+$")
|
||||
|
||||
if selected_provider and selected_provider ~= current_provider then providers.refresh(selected_provider) end
|
||||
|
||||
api.nvim_win_close(winid, true)
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<Up>", function() move_selection("up") end, { buffer = bufnr })
|
||||
vim.keymap.set("n", "<Down>", function() move_selection("down") end, { buffer = bufnr })
|
||||
vim.keymap.set("n", "<CR>", select_provider, { buffer = bufnr })
|
||||
vim.keymap.set("n", "q", function() api.nvim_win_close(winid, true) end, { buffer = bufnr })
|
||||
end
|
||||
|
||||
function Sidebar:create_selected_files_container()
|
||||
if self.selected_files_container then self.selected_files_container:unmount() end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user