refactor(_utils.health): reorganize module
This commit is contained in:
parent
6e70be0ef9
commit
3e51e15dac
2 changed files with 36 additions and 36 deletions
|
|
@ -1,17 +1,26 @@
|
||||||
return {
|
local h = vim.health or require "health"
|
||||||
---@param lib string
|
local health = {}
|
||||||
---@return boolean
|
|
||||||
lualib_is_found = function(lib)
|
|
||||||
local is_found, _ = pcall(require, lib)
|
|
||||||
return is_found
|
|
||||||
end,
|
|
||||||
|
|
||||||
---@param bin string
|
health.start = h.start or h.report_start
|
||||||
---@return boolean
|
health.ok = h.ok or h.report_ok
|
||||||
binary_is_found = function(bin)
|
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
|
if vim.fn.executable(bin) == 1 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end,
|
end
|
||||||
}
|
|
||||||
|
return health
|
||||||
|
|
|
||||||
|
|
@ -2,15 +2,6 @@ local health = {}
|
||||||
local cmd = require("gopher.config").commands
|
local cmd = require("gopher.config").commands
|
||||||
local u = require "gopher._utils.health"
|
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 = {
|
local deps = {
|
||||||
plugin = {
|
plugin = {
|
||||||
{ lib = "dap", msg = "required for `gopher.dap`", optional = true },
|
{ lib = "dap", msg = "required for `gopher.dap`", optional = true },
|
||||||
|
|
@ -36,29 +27,29 @@ local deps = {
|
||||||
}
|
}
|
||||||
|
|
||||||
function health.check()
|
function health.check()
|
||||||
h.start "required plugins"
|
u.start "required plugins"
|
||||||
for _, plugin in ipairs(deps.plugin) do
|
for _, plugin in ipairs(deps.plugin) do
|
||||||
if u.lualib_is_found(plugin.lib) then
|
if u.is_lualib_found(plugin.lib) then
|
||||||
h.ok(plugin.lib .. " installed")
|
u.ok(plugin.lib .. " installed")
|
||||||
else
|
else
|
||||||
if plugin.optional then
|
if plugin.optional then
|
||||||
h.warn(plugin.lib .. " not found, " .. plugin.msg)
|
u.warn(plugin.lib .. " not found, " .. plugin.msg)
|
||||||
else
|
else
|
||||||
h.error(plugin.lib .. " not found, " .. plugin.msg)
|
u.error(plugin.lib .. " not found, " .. plugin.msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
h.start "required binaries"
|
u.start "required binaries"
|
||||||
h.info "all those binaries can be installed by `:GoInstallDeps`"
|
u.info "all those binaries can be installed by `:GoInstallDeps`"
|
||||||
for _, bin in ipairs(deps.bin) do
|
for _, bin in ipairs(deps.bin) do
|
||||||
if u.binary_is_found(bin.bin) then
|
if u.is_lualib_found(bin.bin) then
|
||||||
h.ok(bin.bin .. " installed")
|
u.ok(bin.bin .. " installed")
|
||||||
else
|
else
|
||||||
if bin.optional then
|
if bin.optional then
|
||||||
h.warn(bin.bin .. " not found, " .. bin.msg)
|
u.warn(bin.bin .. " not found, " .. bin.msg)
|
||||||
else
|
else
|
||||||
h.error(bin.bin .. " not found, " .. bin.msg)
|
u.error(bin.bin .. " not found, " .. bin.msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue