mirror of
https://github.com/folke/snacks.nvim
synced 2025-08-06 19:58:22 +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
|
---@return string? cmd, string[]? args
|
||||||
function M.get_cmd(opts)
|
function M.get_cmd(cmd)
|
||||||
opts = opts or {}
|
|
||||||
local checked = {} ---@type string[]
|
local checked = {} ---@type string[]
|
||||||
for _, command in ipairs(commands) do
|
for _, command in ipairs(commands) do
|
||||||
if
|
if command.enabled ~= false and command.available ~= false and (not cmd or vim.tbl_contains(command.cmd, cmd)) then
|
||||||
command.enabled ~= false
|
|
||||||
and command.available ~= false
|
|
||||||
and (not opts.cmd or vim.tbl_contains(command.cmd, opts.cmd))
|
|
||||||
then
|
|
||||||
if command.available then
|
if command.available then
|
||||||
assert(type(command.available) == "string", "available must be a string")
|
assert(type(command.available) == "string", "available must be a string")
|
||||||
return command.available, vim.deepcopy(command.args)
|
return command.available, vim.deepcopy(command.args)
|
||||||
|
@ -44,17 +39,21 @@ function M.get_cmd(opts)
|
||||||
command.available = false
|
command.available = false
|
||||||
end
|
end
|
||||||
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)
|
checked = vim.tbl_map(function(c)
|
||||||
return "`" .. c .. "`"
|
return "`" .. c .. "`"
|
||||||
end, checked)
|
end, checked)
|
||||||
Snacks.notify.error("No supported finder found:\n- " .. table.concat(checked, "\n-"))
|
Snacks.notify.error("No supported finder found:\n- " .. table.concat(checked, "\n-"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function M.get_fd()
|
||||||
|
return M.get_cmd("fd")
|
||||||
|
end
|
||||||
|
|
||||||
---@param opts snacks.picker.files.Config
|
---@param opts snacks.picker.files.Config
|
||||||
---@param filter snacks.picker.Filter
|
---@param filter snacks.picker.Filter
|
||||||
local function get_cmd(opts, 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
|
if not cmd or not args then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -77,7 +77,11 @@ function M.projects(opts, ctx)
|
||||||
local dev = type(opts.dev) == "string" and { opts.dev } or opts.dev or {}
|
local dev = type(opts.dev) == "string" and { opts.dev } or opts.dev or {}
|
||||||
---@cast dev string[]
|
---@cast dev string[]
|
||||||
vim.list_extend(args, vim.tbl_map(vim.fs.normalize, dev))
|
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
|
---@async
|
||||||
---@param cb async fun(item: snacks.picker.finder.Item)
|
---@param cb async fun(item: snacks.picker.finder.Item)
|
||||||
return function(cb)
|
return function(cb)
|
||||||
|
@ -97,6 +101,10 @@ function M.projects(opts, ctx)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if not proc then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
---@async
|
---@async
|
||||||
proc(function(item)
|
proc(function(item)
|
||||||
local path = item.text
|
local path = item.text
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue