refactor(health): use vim.health since it's new standard
This commit is contained in:
parent
6016ca57d4
commit
b4b0b3ec42
2 changed files with 37 additions and 48 deletions
|
|
@ -1,33 +0,0 @@
|
||||||
local h = vim.health or require "health"
|
|
||||||
local health = {}
|
|
||||||
|
|
||||||
health.start = h.start or h.report_start
|
|
||||||
health.ok = h.ok or h.report_ok
|
|
||||||
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
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
---@param ft string
|
|
||||||
---@return boolean
|
|
||||||
function health.is_treesitter_parser_available(ft)
|
|
||||||
local ok, parser = pcall(vim.treesitter.get_parser, 0, ft)
|
|
||||||
return ok and parser ~= nil
|
|
||||||
end
|
|
||||||
|
|
||||||
return health
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
local health = {}
|
local health = {}
|
||||||
local cmd = require("gopher.config").commands
|
local cmd = require("gopher.config").commands
|
||||||
local u = require "gopher._utils.health_util"
|
|
||||||
|
|
||||||
local deps = {
|
local deps = {
|
||||||
plugin = {
|
plugin = {
|
||||||
|
|
@ -26,36 +25,59 @@ local deps = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---@param module string
|
||||||
|
---@return boolean
|
||||||
|
local function is_lualib_found(module)
|
||||||
|
local is_found, _ = pcall(require, module)
|
||||||
|
return is_found
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param bin string
|
||||||
|
---@return boolean
|
||||||
|
local function is_binary_found(bin)
|
||||||
|
if vim.fn.executable(bin) == 1 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param ft string
|
||||||
|
---@return boolean
|
||||||
|
local function is_treesitter_parser_available(ft)
|
||||||
|
local ok, parser = pcall(vim.treesitter.get_parser, 0, ft)
|
||||||
|
return ok and parser ~= nil
|
||||||
|
end
|
||||||
|
|
||||||
function health.check()
|
function health.check()
|
||||||
u.start "required plugins"
|
vim.health.start "required plugins"
|
||||||
for _, plugin in ipairs(deps.plugin) do
|
for _, plugin in ipairs(deps.plugin) do
|
||||||
if u.is_lualib_found(plugin.lib) then
|
if is_lualib_found(plugin.lib) then
|
||||||
u.ok(plugin.lib .. " installed")
|
vim.health.ok(plugin.lib .. " installed")
|
||||||
else
|
else
|
||||||
u.error(plugin.lib .. " not found, " .. plugin.msg)
|
vim.health.error(plugin.lib .. " not found, " .. plugin.msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
u.start "required binaries"
|
vim.health.start "required binaries"
|
||||||
u.info "all those binaries can be installed by `:GoInstallDeps`"
|
vim.health.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.is_binary_found(bin.bin) then
|
if is_binary_found(bin.bin) then
|
||||||
u.ok(bin.bin .. " installed")
|
vim.health.ok(bin.bin .. " installed")
|
||||||
else
|
else
|
||||||
if bin.optional then
|
if bin.optional then
|
||||||
u.warn(bin.bin .. " not found, " .. bin.msg)
|
vim.health.warn(bin.bin .. " not found, " .. bin.msg)
|
||||||
else
|
else
|
||||||
u.error(bin.bin .. " not found, " .. bin.msg)
|
vim.health.error(bin.bin .. " not found, " .. bin.msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
u.start "required treesitter parsers"
|
vim.health.start "required treesitter parsers"
|
||||||
for _, parser in ipairs(deps.treesitter) do
|
for _, parser in ipairs(deps.treesitter) do
|
||||||
if u.is_treesitter_parser_available(parser.parser) then
|
if is_treesitter_parser_available(parser.parser) then
|
||||||
u.ok(parser.parser .. " parser installed")
|
vim.health.ok(parser.parser .. " parser installed")
|
||||||
else
|
else
|
||||||
u.error(parser.parser .. " parser not found, " .. parser.msg)
|
vim.health.error(parser.parser .. " parser not found, " .. parser.msg)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue