healthcheck: refactoring, remove deprecation wanings (#35)

* refactor(checkhealth): remove deprecation warnings, complete rewrite

* refactor(checkhealth): rename util file

* style(healthchecker): reformat lua in vim file

* refactor(health): move all report function into table
This commit is contained in:
Smirnov Oleksandr 2023-07-17 18:31:21 +03:00 committed by GitHub
parent 03cabf675c
commit 9d6bc761d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 52 additions and 29 deletions

View file

@ -1,3 +1,3 @@
function! health#gopher#check() function! health#gopher#check()
lua require"gopher.health".check() lua require("gopher.health").check()
endfunction endfunction

View file

@ -1,44 +1,67 @@
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 h = {
_required = { start = _h.start or _h.report_start,
plugins = { ok = _h.ok or _h.report_ok,
{ lib = "plenary", help = requried_for_work_msg }, warn = _h.warn or _h.report_warn,
{ lib = "nvim-treesitter", help = requried_for_work_msg }, error = _h.error or _h.report_error,
{ lib = "dap", help = "Required for set upping debugger" }, info = _h.info or _h.report_info,
}
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 },
}, },
binarys = { bin = {
{ bin = c.go, help = "required for GoMod, GoGet, GoGenerate command" }, {
{ bin = c.gomodifytags, help = "required for modify struct tags" }, bin = cmd.go,
{ bin = c.impl, help = "required for interface implementing" }, msg = "required for :GoGet, :GoMod, :GoGenerate, :GoWork, :GoInstallDeps",
{ bin = c.gotests, help = "required for test(s) generation" }, optional = false,
{ bin = c.dlv, help = "required for debugger(nvim-dap)" },
}, },
{ bin = cmd.gomodifytags, msg = "required for :GoTagAdd, :GoTagRm", optional = false },
{ bin = cmd.impl, msg = "required for :GoImpl", optional = false },
{ bin = cmd.iferr, msg = "required for :GoIfErr", optional = false },
{
bin = cmd.gotests,
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" h.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.") h.ok(plugin.lib .. " installed")
else else
health.report_error(plugin.lib .. " not found. " .. plugin.help) if plugin.optional then
end h.warn(plugin.lib .. " not found, " .. plugin.msg)
end
health.report_start "Required go tools"
for _, binary in ipairs(M._required.binarys) do
if u.binary_is_found(binary.bin) then
health.report_ok(binary.bin .. " installed")
else else
health.report_warn(binary.bin .. " is not installed but " .. binary.help) h.error(plugin.lib .. " not found, " .. plugin.msg)
end end
end end
end end
return M h.start "required binaries"
h.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")
else
if bin.optional then
h.warn(bin.bin .. " not found, " .. bin.msg)
else
h.error(bin.bin .. " not found, " .. bin.msg)
end
end
end
end
return health