refactor(health): mark all bin deps as required, check if vim version is 0.10 or higher

This commit is contained in:
Oleksandr Smirnov 2025-09-16 15:09:49 +03:00
parent f4809cd2ec
commit e8d53840d4
No known key found for this signature in database

View file

@ -1,62 +1,58 @@
local c = require("gopher.config").commands
local health = {} local health = {}
local cmd = require("gopher.config").commands
local deps = { local deps = {
vim_version = "nvim-0.10",
bin = { bin = {
{ {
bin = cmd.go, bin = c.go,
msg = "required for `:GoGet`, `:GoMod`, `:GoGenerate`, `:GoWork`, `:GoInstallDeps`, `:GoInstallDepsSync`", msg = "required for `:GoGet`, `:GoMod`, `:GoGenerate`, `:GoWork`, `:GoInstallDeps`, `:GoInstallDepsSync`",
optional = false,
},
{ bin = cmd.gomodifytags, msg = "required for `:GoTagAdd`, `:GoTagRm`", optional = true },
{ bin = cmd.impl, msg = "required for `:GoImpl`", optional = true },
{ bin = cmd.iferr, msg = "required for `:GoIfErr`", optional = true },
{
bin = cmd.gotests,
msg = "required for `:GoTestAdd`, `:GoTestsAll`, `:GoTestsExp`",
optional = true,
}, },
{ bin = c.gomodifytags, msg = "required for `:GoTagAdd`, `:GoTagRm`" },
{ bin = c.impl, msg = "required for `:GoImpl`" },
{ bin = c.iferr, msg = "required for `:GoIfErr`" },
{ bin = c.gotests, msg = "required for `:GoTestAdd`, `:GoTestsAll`, `:GoTestsExp`" },
}, },
treesitter = { treesitter = {
{ parser = "go", msg = "required for most of the parts of `gopher.nvim`" }, { parser = "go", msg = "required for most of the parts of `gopher.nvim`" },
}, },
} }
---@param bin string ---@param bin {bin:string, msg:string, optional:boolean}
---@return boolean local function check_binary(bin)
local function is_binary_found(bin) if vim.fn.executable(bin.bin) == 1 then
return vim.fn.executable(bin) == 1 vim.health.ok(bin.bin .. " is found oh PATH: `" .. vim.fn.exepath(bin.bin) .. "`")
else
vim.health.error(bin.bin .. " not found on PATH, " .. bin.msg)
end
end end
---@param ft string ---@param ts {parser:string, msg:string}
---@return boolean local function check_treesitter(ts)
local function is_treesitter_parser_available(ft) local ok, parser = pcall(vim.treesitter.get_parser, 0, ts.parser)
local ok, parser = pcall(vim.treesitter.get_parser, 0, ft) if ok and parser ~= nil then
return ok and parser ~= nil vim.health.ok("`" .. ts.parser .. "` parser is installed")
else
vim.health.error("`" .. ts.parser .. "` parser not found")
end
end end
function health.check() function health.check()
vim.health.start "required binaries" vim.health.start "Neovim version"
vim.health.info "all those binaries can be installed by `:GoInstallDeps`" if vim.fn.has(deps.vim_version) == 1 then
for _, bin in ipairs(deps.bin) do vim.health.ok "Neovim version is compatible"
if is_binary_found(bin.bin) then
vim.health.ok(bin.bin .. " installed")
else else
if bin.optional then vim.health.error(deps.vim_version .. " or newer is required")
vim.health.warn(bin.bin .. " not found, " .. bin.msg)
else
vim.health.error(bin.bin .. " not found, " .. bin.msg)
end
end
end end
vim.health.start "required treesitter parsers" vim.health.start "Required binaries (those can be installed with `:GoInstallDeps`)"
for _, parser in ipairs(deps.treesitter) do for _, bin in ipairs(deps.bin) do
if is_treesitter_parser_available(parser.parser) then check_binary(bin)
vim.health.ok(parser.parser .. " parser installed")
else
vim.health.error(parser.parser .. " parser not found, " .. parser.msg)
end end
vim.health.start "Treesitter"
for _, parser in ipairs(deps.treesitter) do
check_treesitter(parser)
end end
end end