From 860a47978946506a44aa2d576e8692cdb23aa6d8 Mon Sep 17 00:00:00 2001 From: Sam Wall Date: Wed, 4 Jun 2025 18:42:50 +0100 Subject: [PATCH] feat: add terminal buffers to selected files (#2077) Co-authored-by: Samuel Wall --- lua/avante/file_selector.lua | 5 +++-- lua/avante/utils/init.lua | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lua/avante/file_selector.lua b/lua/avante/file_selector.lua index 2526652..9bc4a6d 100644 --- a/lua/avante/file_selector.lua +++ b/lua/avante/file_selector.lua @@ -14,7 +14,7 @@ local FileSelector = {} ---@alias FileSelectorHandler fun(self: FileSelector, on_select: fun(filepaths: string[] | nil)): nil -local function has_scheme(path) return path:find("^%w+://") ~= nil end +local function has_scheme(path) return path:find("^(?!term://)%w+://") ~= nil end function FileSelector:process_directory(absolute_path, project_root) if absolute_path:sub(-1) == Utils.path_sep then absolute_path = absolute_path:sub(1, -2) end @@ -85,7 +85,8 @@ end function FileSelector:add_selected_file(filepath) if not filepath or filepath == "" then return end - local absolute_path = filepath:sub(1, 1) == "/" and filepath or Utils.join_paths(Utils.get_project_root(), filepath) + local absolute_path = (filepath:sub(1, 1) == "/" or filepath:sub(1, 7) == "term://") and filepath + or Utils.join_paths(Utils.get_project_root(), filepath) local stat = vim.loop.fs_stat(absolute_path) if stat and stat.type == "directory" then diff --git a/lua/avante/utils/init.lua b/lua/avante/utils/init.lua index 84f85b0..e1a841b 100644 --- a/lua/avante/utils/init.lua +++ b/lua/avante/utils/init.lua @@ -1094,7 +1094,7 @@ end ---@return string[]|nil lines ---@return string|nil error function M.read_file_from_buf_or_disk(filepath) - local abs_path = M.join_paths(M.get_project_root(), filepath) + local abs_path = filepath:sub(1, 7) == "term://" and filepath or M.join_paths(M.get_project_root(), filepath) --- Lookup if the file is loaded in a buffer local bufnr = vim.fn.bufnr(abs_path) if bufnr ~= -1 and vim.api.nvim_buf_is_loaded(bufnr) then