mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-04 18:58:12 +00:00
fix(picker.projects): use fd or fdfind
This commit is contained in:
parent
8deea64dba
commit
270250cf46
2 changed files with 18 additions and 11 deletions
|
@ -19,17 +19,12 @@ local commands = {
|
|||
},
|
||||
}
|
||||
|
||||
---@param opts? snacks.picker.files.Config
|
||||
---@param cmd? string
|
||||
---@return string? cmd, string[]? args
|
||||
function M.get_cmd(opts)
|
||||
opts = opts or {}
|
||||
function M.get_cmd(cmd)
|
||||
local checked = {} ---@type string[]
|
||||
for _, command in ipairs(commands) do
|
||||
if
|
||||
command.enabled ~= false
|
||||
and command.available ~= false
|
||||
and (not opts.cmd or vim.tbl_contains(command.cmd, opts.cmd))
|
||||
then
|
||||
if command.enabled ~= false and command.available ~= false and (not cmd or vim.tbl_contains(command.cmd, cmd)) then
|
||||
if command.available then
|
||||
assert(type(command.available) == "string", "available must be a string")
|
||||
return command.available, vim.deepcopy(command.args)
|
||||
|
@ -44,17 +39,21 @@ function M.get_cmd(opts)
|
|||
command.available = false
|
||||
end
|
||||
end
|
||||
checked = #checked == 0 and opts.cmd and { opts.cmd } or checked
|
||||
checked = #checked == 0 and cmd and { cmd } or checked
|
||||
checked = vim.tbl_map(function(c)
|
||||
return "`" .. c .. "`"
|
||||
end, checked)
|
||||
Snacks.notify.error("No supported finder found:\n- " .. table.concat(checked, "\n-"))
|
||||
end
|
||||
|
||||
function M.get_fd()
|
||||
return M.get_cmd("fd")
|
||||
end
|
||||
|
||||
---@param opts snacks.picker.files.Config
|
||||
---@param filter snacks.picker.Filter
|
||||
local function get_cmd(opts, filter)
|
||||
local cmd, args = M.get_cmd(opts)
|
||||
local cmd, args = M.get_cmd(opts.cmd)
|
||||
if not cmd or not args then
|
||||
return
|
||||
end
|
||||
|
|
|
@ -77,7 +77,11 @@ function M.projects(opts, ctx)
|
|||
local dev = type(opts.dev) == "string" and { opts.dev } or opts.dev or {}
|
||||
---@cast dev string[]
|
||||
vim.list_extend(args, vim.tbl_map(vim.fs.normalize, dev))
|
||||
local proc = require("snacks.picker.source.proc").proc({ cmd = "fd", args = args, notify = false }, ctx)
|
||||
local fd = require("snacks.picker.source.files").get_fd()
|
||||
if not fd then
|
||||
Snacks.notify.warn("`fd` or `fdfind` is required for projects")
|
||||
end
|
||||
local proc = fd and require("snacks.picker.source.proc").proc({ cmd = fd, args = args, notify = false }, ctx)
|
||||
---@async
|
||||
---@param cb async fun(item: snacks.picker.finder.Item)
|
||||
return function(cb)
|
||||
|
@ -97,6 +101,10 @@ function M.projects(opts, ctx)
|
|||
end
|
||||
end
|
||||
|
||||
if not proc then
|
||||
return
|
||||
end
|
||||
|
||||
---@async
|
||||
proc(function(item)
|
||||
local path = item.text
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue