fix(health): better health checks for picker. Closes #917

This commit is contained in:
Folke Lemaitre 2025-02-04 17:24:03 +01:00
parent c494ddc57a
commit 427f036c65
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040
2 changed files with 10 additions and 6 deletions

View file

@ -14,7 +14,7 @@ local M = setmetatable({}, {
---@class snacks.health.Tool ---@class snacks.health.Tool
---@field cmd string|string[] ---@field cmd string|string[]
---@field version? string ---@field version? string|false
---@field enabled? boolean ---@field enabled? boolean
---@alias snacks.health.Tool.spec (string|snacks.health.Tool)[]|snacks.health.Tool|string ---@alias snacks.health.Tool.spec (string|snacks.health.Tool)[]|snacks.health.Tool|string
@ -91,10 +91,13 @@ function M.have_tool(tools)
vim.list_extend(all, cmds) vim.list_extend(all, cmds)
for _, cmd in ipairs(cmds) do for _, cmd in ipairs(cmds) do
if vim.fn.executable(cmd) == 1 then if vim.fn.executable(cmd) == 1 then
local version = vim.fn.system(cmd .. " --version") or "" local version = tool.version == false and "" or vim.fn.system(cmd .. " --version") or ""
version = vim.trim(vim.split(version, "\n")[1]) version = vim.trim(vim.split(version, "\n")[1])
if tool_version and tool_version > vim.version.parse(version) then if tool_version and tool_version > vim.version.parse(version) then
M.error("'" .. cmd .. "' `" .. version .. "` is too old, expected `" .. tool.version .. "`") M.error("'" .. cmd .. "' `" .. version .. "` is too old, expected `" .. tool.version .. "`")
elseif tool.version == false then
M.ok("'" .. cmd .. "'")
version_ok = true
else else
M.ok("'" .. cmd .. "' `" .. version .. "`") M.ok("'" .. cmd .. "' `" .. version .. "`")
version_ok = true version_ok = true

View file

@ -27,9 +27,10 @@ function M.health()
local have_fd, version_fd = Snacks.health.have_tool({ local have_fd, version_fd = Snacks.health.have_tool({
{ cmd = { "fd", "fdfind" }, version = "v8.4" }, { cmd = { "fd", "fdfind" }, version = "v8.4" },
}) })
local have_find = Snacks.health.have_tool({ local have_find = have_fd
{ cmd = "find", enabled = jit.os:find("Windows") == nil }, or (jit.os:find("Windows") == nil and Snacks.health.have_tool({
}) { cmd = "find", version = false },
}))
if have_rg or have_fd or have_find then if have_rg or have_fd or have_find then
Snacks.health.ok("`Snacks.picker.files()` is available") Snacks.health.ok("`Snacks.picker.files()` is available")
else else
@ -37,7 +38,7 @@ function M.health()
end end
if not have_fd or not version_fd then if not have_fd or not version_fd then
Snacks.health.error("'fd' `v8.4` is required for `Snacks.picker.explorer()`") Snacks.health.error("'fd' `v8.4` is required for searching with `Snacks.picker.explorer()`")
else else
Snacks.health.ok("`Snacks.picker.explorer()` is available") Snacks.health.ok("`Snacks.picker.explorer()` is available")
end end