show provider selector
This commit is contained in:
parent
c8460ca574
commit
1ce3efbfe6
@ -256,8 +256,12 @@ M._defaults = {
|
|||||||
files = {
|
files = {
|
||||||
add_current = "<leader>ac", -- Add current buffer to selected files
|
add_current = "<leader>ac", -- Add current buffer to selected files
|
||||||
},
|
},
|
||||||
|
providers = {
|
||||||
|
show = "<leader>ap", -- Show providers selector
|
||||||
|
},
|
||||||
},
|
},
|
||||||
windows = {
|
windows = {
|
||||||
|
|
||||||
---@alias AvantePosition "right" | "left" | "top" | "bottom" | "smart"
|
---@alias AvantePosition "right" | "left" | "top" | "bottom" | "smart"
|
||||||
position = "right",
|
position = "right",
|
||||||
wrap = true, -- similar to vim.o.wrap
|
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>(AvanteToggleHint)", function() M.toggle.hint() end)
|
||||||
vim.keymap.set("n", "<Plug>(AvanteToggleSuggestion)", function() M.toggle.suggestion() 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>(AvanteConflictOurs)", function() Diff.choose("ours") end)
|
||||||
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictBoth)", function() Diff.choose("both") 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)
|
vim.keymap.set({ "n", "v" }, "<Plug>(AvanteConflictTheirs)", function() Diff.choose("theirs") end)
|
||||||
@ -121,6 +126,14 @@ H.keymaps = function()
|
|||||||
function() M.toggle.suggestion() end,
|
function() M.toggle.suggestion() end,
|
||||||
{ desc = "avante: toggle suggestion" }
|
{ 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, {
|
Utils.safe_keymap_set("n", Config.mappings.toggle.repomap, function() require("avante.repo_map").show() end, {
|
||||||
desc = "avante: display repo map",
|
desc = "avante: display repo map",
|
||||||
noremap = true,
|
noremap = true,
|
||||||
|
@ -1219,6 +1219,12 @@ end
|
|||||||
--- Initialize the sidebar instance.
|
--- Initialize the sidebar instance.
|
||||||
--- @return avante.Sidebar The Sidebar instance.
|
--- @return avante.Sidebar The Sidebar instance.
|
||||||
function Sidebar:initialize()
|
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.winid = api.nvim_get_current_win()
|
||||||
self.code.bufnr = api.nvim_get_current_buf()
|
self.code.bufnr = api.nvim_get_current_buf()
|
||||||
self.code.selection = Utils.get_visual_selection_and_range()
|
self.code.selection = Utils.get_visual_selection_and_range()
|
||||||
@ -2256,6 +2262,70 @@ function Sidebar:render(opts)
|
|||||||
return self
|
return self
|
||||||
end
|
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()
|
function Sidebar:create_selected_files_container()
|
||||||
if self.selected_files_container then self.selected_files_container:unmount() end
|
if self.selected_files_container then self.selected_files_container:unmount() end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user