feat(file_selector): add intergration with nvim-tree.lua (#1987)

Co-authored-by: doodleEsc <cokie@foxmail.com>
Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
This commit is contained in:
doodleEsc
2025-05-06 00:06:41 +08:00
committed by GitHub
parent e21f1f07bd
commit 0b78b58760
5 changed files with 177 additions and 0 deletions

View File

@@ -249,6 +249,42 @@ function M.add_buffer_files()
sidebar.file_selector:add_buffer_files()
end
function M.add_selected_file(filepath)
local rel_path = Utils.uniform_path(filepath)
local sidebar = require("avante").get()
if not sidebar then
require("avante.api").ask()
sidebar = require("avante").get()
end
if not sidebar:is_open() then sidebar:open({}) end
sidebar.file_selector:add_selected_file(rel_path)
end
function M.remove_selected_file(filepath)
---@diagnostic disable-next-line: undefined-field
local stat = vim.loop.fs_stat(filepath)
local files
if stat and stat.type == "directory" then
files = Utils.scan_directory({ directory = filepath, add_dirs = true })
else
files = { filepath }
end
local sidebar = require("avante").get()
if not sidebar then
require("avante.api").ask()
sidebar = require("avante").get()
end
if not sidebar:is_open() then sidebar:open({}) end
for _, file in ipairs(files) do
local rel_path = Utils.uniform_path(file)
vim.notify(rel_path)
sidebar.file_selector:remove_selected_file(rel_path)
end
end
function M.stop() require("avante.llm").cancel_inflight_request() end
return setmetatable(M, {