refactor(_utils.health): reorganize module

This commit is contained in:
Smirnov Oleksandr 2023-07-19 23:26:09 +03:00
parent 6e70be0ef9
commit 3e51e15dac
2 changed files with 36 additions and 36 deletions

View file

@ -1,17 +1,26 @@
return {
---@param lib string
---@return boolean
lualib_is_found = function(lib)
local is_found, _ = pcall(require, lib)
return is_found
end,
local h = vim.health or require "health"
local health = {}
---@param bin string
---@return boolean
binary_is_found = function(bin)
health.start = h.start or h.report_start
health.ok = h.ok or h.report_ok
health.warn = h.warn or h.report_warn
health.error = h.error or h.report_error
health.info = h.info or h.report_info
---@param module string
---@return boolean
function health.is_lualib_found(module)
local is_found, _ = pcall(require, module)
return is_found
end
---@param bin string
---@return boolean
function health.is_binary_found(bin)
if vim.fn.executable(bin) == 1 then
return true
end
return false
end,
}
end
return health

View file

@ -2,15 +2,6 @@ local health = {}
local cmd = require("gopher.config").commands
local u = require "gopher._utils.health"
local _h = vim.health or require "health"
local h = {
start = _h.start or _h.report_start,
ok = _h.ok or _h.report_ok,
warn = _h.warn or _h.report_warn,
error = _h.error or _h.report_error,
info = _h.info or _h.report_info,
}
local deps = {
plugin = {
{ lib = "dap", msg = "required for `gopher.dap`", optional = true },
@ -36,29 +27,29 @@ local deps = {
}
function health.check()
h.start "required plugins"
u.start "required plugins"
for _, plugin in ipairs(deps.plugin) do
if u.lualib_is_found(plugin.lib) then
h.ok(plugin.lib .. " installed")
if u.is_lualib_found(plugin.lib) then
u.ok(plugin.lib .. " installed")
else
if plugin.optional then
h.warn(plugin.lib .. " not found, " .. plugin.msg)
u.warn(plugin.lib .. " not found, " .. plugin.msg)
else
h.error(plugin.lib .. " not found, " .. plugin.msg)
u.error(plugin.lib .. " not found, " .. plugin.msg)
end
end
end
h.start "required binaries"
h.info "all those binaries can be installed by `:GoInstallDeps`"
u.start "required binaries"
u.info "all those binaries can be installed by `:GoInstallDeps`"
for _, bin in ipairs(deps.bin) do
if u.binary_is_found(bin.bin) then
h.ok(bin.bin .. " installed")
if u.is_lualib_found(bin.bin) then
u.ok(bin.bin .. " installed")
else
if bin.optional then
h.warn(bin.bin .. " not found, " .. bin.msg)
u.warn(bin.bin .. " not found, " .. bin.msg)
else
h.error(bin.bin .. " not found, " .. bin.msg)
u.error(bin.bin .. " not found, " .. bin.msg)
end
end
end