feat(picker): added preliminary support for combining finder results. More info coming soon

This commit is contained in:
Folke Lemaitre 2025-01-15 10:58:31 +01:00
parent 3e39250796
commit 000db17bf9
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
4 changed files with 65 additions and 10 deletions

View file

@ -76,17 +76,32 @@ function M.resolve(v, ...)
end
--- Get the finder
---@param finder string|snacks.picker.finder
---@param finder string|snacks.picker.finder|snacks.picker.finder.multi
---@return snacks.picker.finder
function M.finder(finder)
local nop = function()
Snacks.notify.error("Finder not found:\n```lua\n" .. vim.inspect(finder) .. "\n```", { title = "Snacks Picker" })
end
if not finder or type(finder) == "function" then
return finder
end
if type(finder) == "table" then
---@cast finder snacks.picker.finder.multi
---@type snacks.picker.finder[]
local finders = vim.tbl_map(function(f)
return M.finder(f)
end, finder)
return require("snacks.picker.core.finder").multi(finders)
end
---@cast finder string
local mod, fn = finder:match("^(.-)_(.+)$")
if not (mod and fn) then
mod, fn = finder, finder
end
return require("snacks.picker.source." .. mod)[fn]
local ok, ret = pcall(function()
return require("snacks.picker.source." .. mod)[fn]
end)
return ok and ret or nop
end
local did_setup = false