chore: use of require "health" over vim.fn["health#*"] (#1868)
This commit is contained in:
@@ -1,14 +1,8 @@
|
|||||||
local fn = vim.fn
|
local health = require "health"
|
||||||
local extension_module = require "telescope._extensions"
|
local extension_module = require "telescope._extensions"
|
||||||
local extension_info = require("telescope").extensions
|
local extension_info = require("telescope").extensions
|
||||||
local is_win = vim.api.nvim_call_function("has", { "win32" }) == 1
|
local is_win = vim.api.nvim_call_function("has", { "win32" }) == 1
|
||||||
|
|
||||||
local health_start = vim.fn["health#report_start"]
|
|
||||||
local health_ok = vim.fn["health#report_ok"]
|
|
||||||
local health_warn = vim.fn["health#report_warn"]
|
|
||||||
local health_error = vim.fn["health#report_error"]
|
|
||||||
local health_info = vim.fn["health#report_info"]
|
|
||||||
|
|
||||||
local optional_dependencies = {
|
local optional_dependencies = {
|
||||||
{
|
{
|
||||||
finder_name = "live-grep",
|
finder_name = "live-grep",
|
||||||
@@ -48,7 +42,7 @@ local check_binary_installed = function(package)
|
|||||||
if is_win then
|
if is_win then
|
||||||
binary = binary .. ".exe"
|
binary = binary .. ".exe"
|
||||||
end
|
end
|
||||||
if fn.executable(binary) == 1 then
|
if vim.fn.executable(binary) == 1 then
|
||||||
local handle = io.popen(binary .. " --version")
|
local handle = io.popen(binary .. " --version")
|
||||||
local binary_version = handle:read "*a"
|
local binary_version = handle:read "*a"
|
||||||
handle:close()
|
handle:close()
|
||||||
@@ -66,23 +60,23 @@ local M = {}
|
|||||||
|
|
||||||
M.check = function()
|
M.check = function()
|
||||||
-- Required lua libs
|
-- Required lua libs
|
||||||
health_start "Checking for required plugins"
|
health.report_start "Checking for required plugins"
|
||||||
for _, plugin in ipairs(required_plugins) do
|
for _, plugin in ipairs(required_plugins) do
|
||||||
if lualib_installed(plugin.lib) then
|
if lualib_installed(plugin.lib) then
|
||||||
health_ok(plugin.lib .. " installed.")
|
health.report_ok(plugin.lib .. " installed.")
|
||||||
else
|
else
|
||||||
local lib_not_installed = plugin.lib .. " not found."
|
local lib_not_installed = plugin.lib .. " not found."
|
||||||
if plugin.optional then
|
if plugin.optional then
|
||||||
health_warn(("%s %s"):format(lib_not_installed, plugin.info))
|
health.report_warn(("%s %s"):format(lib_not_installed, plugin.info))
|
||||||
else
|
else
|
||||||
health_error(lib_not_installed)
|
health.report_error(lib_not_installed)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- external dependencies
|
-- external dependencies
|
||||||
-- TODO: only perform checks if user has enabled dependency in their config
|
-- TODO: only perform checks if user has enabled dependency in their config
|
||||||
health_start "Checking external dependencies"
|
health.report_start "Checking external dependencies"
|
||||||
|
|
||||||
for _, opt_dep in pairs(optional_dependencies) do
|
for _, opt_dep in pairs(optional_dependencies) do
|
||||||
for _, package in ipairs(opt_dep.package) do
|
for _, package in ipairs(opt_dep.package) do
|
||||||
@@ -90,9 +84,9 @@ M.check = function()
|
|||||||
if not installed then
|
if not installed then
|
||||||
local err_msg = ("%s: not found."):format(package.name)
|
local err_msg = ("%s: not found."):format(package.name)
|
||||||
if package.optional then
|
if package.optional then
|
||||||
health_warn(("%s %s"):format(err_msg, ("Install %s for extended capabilities"):format(package.url)))
|
health.report_warn(("%s %s"):format(err_msg, ("Install %s for extended capabilities"):format(package.url)))
|
||||||
else
|
else
|
||||||
health_error(
|
health.report_error(
|
||||||
("%s %s"):format(
|
("%s %s"):format(
|
||||||
err_msg,
|
err_msg,
|
||||||
("`%s` finder will not function without %s installed."):format(opt_dep.finder_name, package.url)
|
("`%s` finder will not function without %s installed."):format(opt_dep.finder_name, package.url)
|
||||||
@@ -101,13 +95,13 @@ M.check = function()
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
local eol = version:find "\n"
|
local eol = version:find "\n"
|
||||||
health_ok(("%s: found %s"):format(package.name, version:sub(0, eol - 1) or "(unknown version)"))
|
health.report_ok(("%s: found %s"):format(package.name, version:sub(0, eol - 1) or "(unknown version)"))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Extensions
|
-- Extensions
|
||||||
health_start "===== Installed extensions ====="
|
health.report_start "===== Installed extensions ====="
|
||||||
|
|
||||||
local installed = {}
|
local installed = {}
|
||||||
for extension_name, _ in pairs(extension_info) do
|
for extension_name, _ in pairs(extension_info) do
|
||||||
@@ -118,11 +112,11 @@ M.check = function()
|
|||||||
for _, installed_ext in ipairs(installed) do
|
for _, installed_ext in ipairs(installed) do
|
||||||
local extension_healthcheck = extension_module._health[installed_ext]
|
local extension_healthcheck = extension_module._health[installed_ext]
|
||||||
|
|
||||||
health_start(string.format("Telescope Extension: `%s`", installed_ext))
|
health.report_start(string.format("Telescope Extension: `%s`", installed_ext))
|
||||||
if extension_healthcheck then
|
if extension_healthcheck then
|
||||||
extension_healthcheck()
|
extension_healthcheck()
|
||||||
else
|
else
|
||||||
health_info "No healthcheck provided"
|
health.report_info "No healthcheck provided"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user