diff --git a/lua/avante/file_selector.lua b/lua/avante/file_selector.lua index 99440b8..f26e505 100644 --- a/lua/avante/file_selector.lua +++ b/lua/avante/file_selector.lua @@ -421,9 +421,11 @@ end function FileSelector:add_buffer_files() local buffers = vim.api.nvim_list_bufs() for _, bufnr in ipairs(buffers) do - if vim.api.nvim_buf_is_loaded(bufnr) then + -- Skip invalid or unlisted buffers + if vim.api.nvim_buf_is_valid(bufnr) and vim.bo[bufnr].buflisted then local filepath = vim.api.nvim_buf_get_name(bufnr) - if filepath and filepath ~= "" and not has_scheme(filepath) then + -- Skip empty paths and special buffers (like terminals) + if filepath ~= "" and not has_scheme(filepath) then local relative_path = Utils.relative_path(filepath) self:add_selected_file(relative_path) end