Compare commits

...

5 Commits
test ... main

Author SHA1 Message Date
zhangkun9038@dingtalk.com
010b23851b gitignroe 的bug修复
Some checks failed
Lua CI / unit tests (ubuntu-22.04, v0.10.0/nvim-linux64.tar.gz) (push) Has been cancelled
Lua CI / Check Lua style (push) Has been cancelled
Lua CI / Lint Lua (push) Has been cancelled
2025-02-17 00:58:22 +08:00
zhangkun9038@dingtalk.com
24b9daee42 尝试修复 add file 作为上下文时会找不到文件
Some checks are pending
Lua CI / unit tests (ubuntu-22.04, v0.10.0/nvim-linux64.tar.gz) (push) Waiting to run
Lua CI / Check Lua style (push) Waiting to run
Lua CI / Lint Lua (push) Waiting to run
2025-02-17 00:15:56 +08:00
zhangkun9038@dingtalk.com
11c0d13b9a 尝试修复 add file 作为上下文时会找不到文件
Some checks are pending
Lua CI / unit tests (ubuntu-22.04, v0.10.0/nvim-linux64.tar.gz) (push) Waiting to run
Lua CI / Check Lua style (push) Waiting to run
Lua CI / Lint Lua (push) Waiting to run
2025-02-17 00:01:17 +08:00
zhangkun9038@dingtalk.com
a6288b8357 尝试修复 add file 作为上下文时会找不到文件
Some checks are pending
Lua CI / unit tests (ubuntu-22.04, v0.10.0/nvim-linux64.tar.gz) (push) Waiting to run
Lua CI / Check Lua style (push) Waiting to run
Lua CI / Lint Lua (push) Waiting to run
2025-02-16 23:38:46 +08:00
zhangkun9038@dingtalk.com
183bf7d8b0 revert
Some checks failed
Lua CI / unit tests (ubuntu-22.04, v0.10.0/nvim-linux64.tar.gz) (push) Has been cancelled
Lua CI / Check Lua style (push) Has been cancelled
Lua CI / Lint Lua (push) Has been cancelled
2025-02-14 13:04:34 +08:00
5 changed files with 25 additions and 88 deletions

View File

@ -256,12 +256,8 @@ M._defaults = {
files = {
add_current = "<leader>ac", -- Add current buffer to selected files
},
providers = {
show = "<leader>ap", -- Show providers selector
},
},
windows = {
---@alias AvantePosition "right" | "left" | "top" | "bottom" | "smart"
position = "right",
wrap = true, -- similar to vim.o.wrap

View File

@ -68,11 +68,6 @@ 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)
@ -126,14 +121,6 @@ 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,

View File

@ -1219,12 +1219,6 @@ 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()
@ -2262,70 +2256,6 @@ 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

View File

@ -665,6 +665,19 @@ function M.scan_directory_respect_gitignore(options)
local directory = options.directory
local gitignore_path = directory .. "/.gitignore"
local gitignore_patterns, gitignore_negate_patterns = M.parse_gitignore(gitignore_path)
-- Convert relative paths in gitignore to absolute paths based on project root
local project_root = M.get_project_root()
local function to_absolute_path(pattern)
-- Skip if already absolute path
if pattern:sub(1, 1) == "/" then return pattern end
-- Convert relative path to absolute
return Path:new(project_root, pattern):absolute()
end
gitignore_patterns = vim.tbl_map(to_absolute_path, gitignore_patterns)
gitignore_negate_patterns = vim.tbl_map(to_absolute_path, gitignore_negate_patterns)
return M.scan_directory({
directory = directory,
gitignore_patterns = gitignore_patterns,

View File

@ -81,9 +81,11 @@ function M.detect(opts)
opts.spec = opts.spec or type(vim.g.root_spec) == "table" and vim.g.root_spec or M.spec
opts.buf = (opts.buf == nil or opts.buf == 0) and vim.api.nvim_get_current_buf() or opts.buf
local ret = {} ---@type AvanteRoot[]
for _, spec in ipairs(opts.spec) do
local paths = M.resolve(spec)(opts.buf)
paths = paths or {}
paths = type(paths) == "table" and paths or { paths }
local roots = {} ---@type string[]
@ -100,6 +102,7 @@ function M.detect(opts)
return ret
end
---@type table<number, string>
M.cache = {}
@ -113,14 +116,22 @@ M.cache = {}
function M.get(opts)
opts = opts or {}
local buf = opts.buf or vim.api.nvim_get_current_buf()
local ret = M.cache[buf]
if not ret then
local roots = M.detect({ all = false, buf = buf })
ret = roots[1] and roots[1].paths[1] or vim.uv.cwd()
M.cache[buf] = ret
end
if opts and opts.normalize then return ret end
return Utils.is_win() and ret:gsub("/", "\\") or ret
-- Ensure a non-empty return value
ret = ret ~= "" and ret or vim.uv.cwd()
--- return Utils.is_win() and ret:gsub("/", "\\") or ret
return ret
end
function M.git()