From 692c168e5b3633b18d563ddfce3f656b0e44e375 Mon Sep 17 00:00:00 2001 From: Aaron Pham Date: Sat, 1 Feb 2025 09:46:01 -0500 Subject: [PATCH] fix(file_selector): make sure to flatten selected_paths if picker yields a single string (#1153) --- lua/avante/config.lua | 2 ++ lua/avante/file_selector.lua | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lua/avante/config.lua b/lua/avante/config.lua index 56a2f4a..da5b5b5 100644 --- a/lua/avante/config.lua +++ b/lua/avante/config.lua @@ -252,6 +252,8 @@ M._defaults = { provider = "native", -- Options override for custom providers provider_opts = {}, + --- @type fun(selected_paths: string[] | string | nil): nil + handler = nil, }, suggestion = { debounce = 600, diff --git a/lua/avante/file_selector.lua b/lua/avante/file_selector.lua index 4767b26..f70a329 100644 --- a/lua/avante/file_selector.lua +++ b/lua/avante/file_selector.lua @@ -30,13 +30,16 @@ function FileSelector:process_directory(absolute_path, project_root) self:emit("update") end ----@param selected_paths string[] | nil +---@param selected_paths string | string[] | nil ---@return nil function FileSelector:handle_path_selection(selected_paths) if not selected_paths then return end local project_root = Utils.get_project_root() - for _, selected_path in ipairs(selected_paths) do + -- Convert single string to array if needed + local paths = type(selected_paths) == "string" and { selected_paths } or selected_paths + + for _, selected_path in ipairs(paths) do local absolute_path = Path:new(project_root):joinpath(selected_path):absolute() local stat = vim.loop.fs_stat(absolute_path) @@ -313,7 +316,8 @@ end ---@return nil function FileSelector:show_select_ui() - local function handler(selected_paths) self:handle_path_selection(selected_paths) end + local handler = Config.file_selector.handler + if handler == nil then handler = function(selected_paths) self:handle_path_selection(selected_paths) end end vim.schedule(function() if Config.file_selector.provider == "native" then