refactor(checkhealth): remove deprecation warnings, complete rewrite
This commit is contained in:
parent
03cabf675c
commit
f7593f43b5
1 changed files with 49 additions and 28 deletions
|
|
@ -1,44 +1,65 @@
|
||||||
local c = require("gopher.config").config.commands
|
local health = {}
|
||||||
|
local cmd = require("gopher.config").config.commands
|
||||||
|
local u = require "gopher._utils._health"
|
||||||
|
|
||||||
local requried_for_work_msg = "Gopher.nvim will not work without it!"
|
local _h = vim.health or require "health"
|
||||||
local M = {
|
local start = _h.start or _h.report_start
|
||||||
_required = {
|
local ok = _h.ok or _h.report_ok
|
||||||
plugins = {
|
local warn = _h.warn or _h.report_warn
|
||||||
{ lib = "plenary", help = requried_for_work_msg },
|
local error = _h.error or _h.report_error
|
||||||
{ lib = "nvim-treesitter", help = requried_for_work_msg },
|
local info = _h.info or _h.report_info
|
||||||
{ lib = "dap", help = "Required for set upping debugger" },
|
|
||||||
|
local deps = {
|
||||||
|
plugin = {
|
||||||
|
{ lib = "dap", msg = "required for `gopher.dap`", optional = true },
|
||||||
|
{ lib = "plenary", msg = "required for everyting in gopher.nvim", optional = false },
|
||||||
|
{ lib = "nvim-treesitter", msg = "required for everyting in gopher.nvim", optional = false },
|
||||||
|
},
|
||||||
|
bin = {
|
||||||
|
{
|
||||||
|
bin = cmd.go,
|
||||||
|
msg = "required for :GoGet, :GoMod, :GoGenerate, :GoWork, :GoInstallDeps",
|
||||||
|
optional = false,
|
||||||
},
|
},
|
||||||
binarys = {
|
{ bin = cmd.gomodifytags, msg = "required for :GoTagAdd, :GoTagRm", optional = false },
|
||||||
{ bin = c.go, help = "required for GoMod, GoGet, GoGenerate command" },
|
{ bin = cmd.impl, msg = "required for :GoImpl", optional = false },
|
||||||
{ bin = c.gomodifytags, help = "required for modify struct tags" },
|
{ bin = cmd.iferr, msg = "required for :GoIfErr", optional = false },
|
||||||
{ bin = c.impl, help = "required for interface implementing" },
|
{
|
||||||
{ bin = c.gotests, help = "required for test(s) generation" },
|
bin = cmd.gotests,
|
||||||
{ bin = c.dlv, help = "required for debugger(nvim-dap)" },
|
msg = "required for :GoTestAdd, :GoTestsAll, :GoTestsExp",
|
||||||
|
optional = false,
|
||||||
},
|
},
|
||||||
|
{ bin = cmd.dlv, msg = "required for debugging, (nvim-dap, `gopher.dap`)", optional = true },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
function M.check()
|
function health.check()
|
||||||
local health = vim.health or require "health"
|
start "required plugins"
|
||||||
local u = require "gopher._utils._health"
|
for _, plugin in ipairs(deps.plugin) do
|
||||||
|
|
||||||
health.report_start "Required plugins"
|
|
||||||
for _, plugin in ipairs(M._required.plugins) do
|
|
||||||
if u.lualib_is_found(plugin.lib) then
|
if u.lualib_is_found(plugin.lib) then
|
||||||
health.report_ok(plugin.lib .. " installed.")
|
ok(plugin.lib .. " installed")
|
||||||
else
|
else
|
||||||
health.report_error(plugin.lib .. " not found. " .. plugin.help)
|
if plugin.optional then
|
||||||
|
warn(plugin.lib .. " not found, " .. plugin.msg)
|
||||||
|
else
|
||||||
|
error(plugin.lib .. " not found, " .. plugin.msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
health.report_start "Required go tools"
|
start "required binaries"
|
||||||
for _, binary in ipairs(M._required.binarys) do
|
info "all those binaries can be installed by `:GoInstallDeps`"
|
||||||
if u.binary_is_found(binary.bin) then
|
for _, bin in ipairs(deps.bin) do
|
||||||
health.report_ok(binary.bin .. " installed")
|
if u.binary_is_found(bin.bin) then
|
||||||
|
ok(bin.bin .. " installed")
|
||||||
else
|
else
|
||||||
health.report_warn(binary.bin .. " is not installed but " .. binary.help)
|
if bin.optional then
|
||||||
|
warn(bin.bin .. " not found, " .. bin.msg)
|
||||||
|
else
|
||||||
|
error(bin.bin .. " not found, " .. bin.msg)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return health
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue