Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove deprecation wanings, refactor healthchecker #35

Merged
merged 4 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion autoload/health/gopher.vim
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
function! health#gopher#check()
lua require"gopher.health".check()
lua require("gopher.health").check()
endfunction
File renamed without changes.
79 changes: 51 additions & 28 deletions lua/gopher/health.lua
Original file line number Diff line number Diff line change
@@ -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 M = {
_required = {
plugins = {
{ lib = "plenary", help = requried_for_work_msg },
{ lib = "nvim-treesitter", help = requried_for_work_msg },
{ lib = "dap", help = "Required for set upping debugger" },
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 },
{ 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 = c.go, help = "required for GoMod, GoGet, GoGenerate command" },
{ bin = c.gomodifytags, help = "required for modify struct tags" },
{ bin = c.impl, help = "required for interface implementing" },
{ bin = c.gotests, help = "required for test(s) generation" },
{ 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()
local health = vim.health or require "health"
local u = require "gopher._utils._health"

health.report_start "Required plugins"
for _, plugin in ipairs(M._required.plugins) do
function health.check()
h.start "required plugins"
for _, plugin in ipairs(deps.plugin) do
if u.lualib_is_found(plugin.lib) then
health.report_ok(plugin.lib .. " installed.")
h.ok(plugin.lib .. " installed")
else
health.report_error(plugin.lib .. " not found. " .. plugin.help)
if plugin.optional then
h.warn(plugin.lib .. " not found, " .. plugin.msg)
else
h.error(plugin.lib .. " not found, " .. plugin.msg)
end
end
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")
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
health.report_warn(binary.bin .. " is not installed but " .. binary.help)
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 M
return health