From 6d116fac36f7e82190c7dcf9a1d0b7199306ace5 Mon Sep 17 00:00:00 2001 From: guanghechen <42513619+guanghechen@users.noreply.github.com> Date: Tue, 11 Feb 2025 13:49:00 +0800 Subject: [PATCH] feat(file_selector): support customized file selector method (#1204) --- lua/avante/config.lua | 7 ++++++- lua/avante/file_selector.lua | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/avante/config.lua b/lua/avante/config.lua index 0364d02..85e0771 100644 --- a/lua/avante/config.lua +++ b/lua/avante/config.lua @@ -5,6 +5,11 @@ local Utils = require("avante.utils") +---@class avante.file_selector.IParams +---@field public title string +---@field public filepaths string[] +---@field public handler fun(filepaths: string[]|nil): nil + ---@class avante.CoreConfig: avante.Config local M = {} ---@class avante.Config @@ -327,7 +332,7 @@ M._defaults = { }, --- @class AvanteFileSelectorConfig file_selector = { - --- @alias FileSelectorProvider "native" | "fzf" | "mini.pick" | "snacks" | "telescope" | string + --- @alias FileSelectorProvider "native" | "fzf" | "mini.pick" | "snacks" | "telescope" | string | fun(params: avante.file_selector.IParams): nil provider = "native", -- Options override for custom providers provider_opts = {}, diff --git a/lua/avante/file_selector.lua b/lua/avante/file_selector.lua index 4af6ac6..2b703d1 100644 --- a/lua/avante/file_selector.lua +++ b/lua/avante/file_selector.lua @@ -330,6 +330,11 @@ function FileSelector:show_select_ui() self:snacks_picker_ui(handler) elseif Config.file_selector.provider == "telescope" then self:telescope_ui(handler) + elseif type(Config.file_selector.provider) == "function" then + local title = string.format("%s:", PROMPT_TITLE) ---@type string + local filepaths = self:get_filepaths() ---@type string[] + local params = { title = title, filepaths = filepaths, handler = handler } ---@type avante.file_selector.IParams + Config.file_selector.provider(params) else Utils.error("Unknown file selector provider: " .. Config.file_selector.provider) end