From 09403a26df73661a65c6aef8e40fe71fe4786111 Mon Sep 17 00:00:00 2001 From: yetone Date: Wed, 19 Feb 2025 19:25:59 +0800 Subject: [PATCH] fix: ignore special buffers (#1307) --- lua/avante/file_selector.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/avante/file_selector.lua b/lua/avante/file_selector.lua index 8675ae8..44eb3e8 100644 --- a/lua/avante/file_selector.lua +++ b/lua/avante/file_selector.lua @@ -15,6 +15,8 @@ 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 + function FileSelector:process_directory(absolute_path, project_root) local files = scan.scan_dir(absolute_path, { hidden = false, @@ -108,7 +110,7 @@ function FileSelector:add_current_buffer() local filepath = vim.api.nvim_buf_get_name(current_buf) -- Only process if it's a real file buffer - if filepath and filepath ~= "" and not vim.startswith(filepath, "avante://") then + if filepath and filepath ~= "" and not has_scheme(filepath) then local relative_path = require("avante.utils").relative_path(filepath) -- Check if file is already in list @@ -410,7 +412,7 @@ function FileSelector:add_buffer_files() for _, bufnr in ipairs(buffers) do if vim.api.nvim_buf_is_loaded(bufnr) then local filepath = vim.api.nvim_buf_get_name(bufnr) - if filepath and filepath ~= "" and not vim.startswith(filepath, "avante://") then + if filepath and filepath ~= "" and not has_scheme(filepath) then local relative_path = Utils.relative_path(filepath) self:add_selected_file(relative_path) end