2022-05-31 11:10:18 -07:00
|
|
|
local M = {}
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
local s_output = {} ---@type string[]
|
2023-04-15 14:40:48 -07:00
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- Returns the fold text of the current healthcheck section
|
2023-06-06 08:42:26 -07:00
|
|
|
function M.foldtext()
|
|
|
|
local foldtext = vim.fn.foldtext()
|
|
|
|
|
|
|
|
if vim.bo.filetype ~= 'checkhealth' then
|
|
|
|
return foldtext
|
|
|
|
end
|
|
|
|
|
|
|
|
if vim.b.failedchecks == nil then
|
|
|
|
vim.b.failedchecks = vim.empty_dict()
|
|
|
|
end
|
|
|
|
|
|
|
|
if vim.b.failedchecks[foldtext] == nil then
|
|
|
|
local warning = '- WARNING '
|
|
|
|
local warninglen = string.len(warning)
|
|
|
|
local err = '- ERROR '
|
|
|
|
local errlen = string.len(err)
|
|
|
|
local failedchecks = vim.b.failedchecks
|
|
|
|
failedchecks[foldtext] = false
|
|
|
|
|
|
|
|
local foldcontent = vim.api.nvim_buf_get_lines(0, vim.v.foldstart - 1, vim.v.foldend, false)
|
|
|
|
for _, line in ipairs(foldcontent) do
|
|
|
|
if string.sub(line, 1, warninglen) == warning or string.sub(line, 1, errlen) == err then
|
|
|
|
failedchecks[foldtext] = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
vim.b.failedchecks = failedchecks
|
|
|
|
end
|
|
|
|
|
|
|
|
return vim.b.failedchecks[foldtext] and '+WE' .. foldtext:sub(4) or foldtext
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- @param path string path to search for the healthcheck
|
|
|
|
--- @return string[] { name, func, type } representing a healthcheck
|
2023-04-15 14:40:48 -07:00
|
|
|
local function filepath_to_healthcheck(path)
|
|
|
|
path = vim.fs.normalize(path)
|
2023-12-13 06:04:24 -07:00
|
|
|
local name --- @type string
|
|
|
|
local func --- @type string
|
|
|
|
local filetype --- @type string
|
2023-04-15 14:40:48 -07:00
|
|
|
if path:find('vim$') then
|
|
|
|
name = vim.fs.basename(path):gsub('%.vim$', '')
|
|
|
|
func = 'health#' .. name .. '#check'
|
|
|
|
filetype = 'v'
|
|
|
|
else
|
|
|
|
local subpath = path:gsub('.*lua/', '')
|
|
|
|
if vim.fs.basename(subpath) == 'health.lua' then
|
|
|
|
-- */health.lua
|
2023-12-13 06:04:24 -07:00
|
|
|
name = assert(vim.fs.dirname(subpath))
|
2023-04-15 14:40:48 -07:00
|
|
|
else
|
|
|
|
-- */health/init.lua
|
2023-12-13 06:04:24 -07:00
|
|
|
name = assert(vim.fs.dirname(assert(vim.fs.dirname(subpath))))
|
2023-04-15 14:40:48 -07:00
|
|
|
end
|
|
|
|
name = name:gsub('/', '.')
|
|
|
|
|
|
|
|
func = 'require("' .. name .. '.health").check()'
|
|
|
|
filetype = 'l'
|
|
|
|
end
|
|
|
|
return { name, func, filetype }
|
2022-05-31 11:10:18 -07:00
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- @param plugin_names string
|
|
|
|
--- @return table<any,string[]> { {name, func, type}, ... } representing healthchecks
|
2023-04-15 14:40:48 -07:00
|
|
|
local function get_healthcheck_list(plugin_names)
|
2023-12-13 06:04:24 -07:00
|
|
|
local healthchecks = {} --- @type table<any,string[]>
|
|
|
|
local plugin_names_list = vim.split(plugin_names, ' ')
|
|
|
|
for _, p in pairs(plugin_names_list) do
|
2023-04-15 14:40:48 -07:00
|
|
|
-- support vim/lsp/health{/init/}.lua as :checkhealth vim.lsp
|
|
|
|
|
|
|
|
p = p:gsub('%.', '/')
|
|
|
|
p = p:gsub('*', '**')
|
|
|
|
|
|
|
|
local paths = vim.api.nvim_get_runtime_file('autoload/health/' .. p .. '.vim', true)
|
|
|
|
vim.list_extend(
|
|
|
|
paths,
|
|
|
|
vim.api.nvim_get_runtime_file('lua/**/' .. p .. '/health/init.lua', true)
|
|
|
|
)
|
|
|
|
vim.list_extend(paths, vim.api.nvim_get_runtime_file('lua/**/' .. p .. '/health.lua', true))
|
|
|
|
|
|
|
|
if vim.tbl_count(paths) == 0 then
|
|
|
|
healthchecks[#healthchecks + 1] = { p, '', '' } -- healthcheck not found
|
|
|
|
else
|
2023-12-13 06:04:24 -07:00
|
|
|
local unique_paths = {} --- @type table<string, boolean>
|
2023-04-15 14:40:48 -07:00
|
|
|
for _, v in pairs(paths) do
|
|
|
|
unique_paths[v] = true
|
|
|
|
end
|
|
|
|
paths = {}
|
|
|
|
for k, _ in pairs(unique_paths) do
|
|
|
|
paths[#paths + 1] = k
|
|
|
|
end
|
|
|
|
|
|
|
|
for _, v in ipairs(paths) do
|
|
|
|
healthchecks[#healthchecks + 1] = filepath_to_healthcheck(v)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return healthchecks
|
2022-05-31 11:10:18 -07:00
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- @param plugin_names string
|
|
|
|
--- @return table<string, string[]> {name: [func, type], ..} representing healthchecks
|
2023-04-15 14:40:48 -07:00
|
|
|
local function get_healthcheck(plugin_names)
|
|
|
|
local health_list = get_healthcheck_list(plugin_names)
|
2023-12-13 06:04:24 -07:00
|
|
|
local healthchecks = {} --- @type table<string, string[]>
|
2023-04-15 14:40:48 -07:00
|
|
|
for _, c in pairs(health_list) do
|
|
|
|
if c[1] ~= 'vim' then
|
|
|
|
healthchecks[c[1]] = { c[2], c[3] }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return healthchecks
|
2022-05-31 11:10:18 -07:00
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- Indents lines *except* line 1 of a string if it contains newlines.
|
|
|
|
---
|
|
|
|
--- @param s string
|
|
|
|
--- @param columns integer
|
|
|
|
--- @return string
|
2023-04-15 14:40:48 -07:00
|
|
|
local function indent_after_line1(s, columns)
|
|
|
|
local lines = vim.split(s, '\n')
|
|
|
|
local indent = string.rep(' ', columns)
|
|
|
|
for i = 2, #lines do
|
|
|
|
lines[i] = indent .. lines[i]
|
|
|
|
end
|
|
|
|
return table.concat(lines, '\n')
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- Changes ':h clipboard' to ':help |clipboard|'.
|
|
|
|
---
|
|
|
|
--- @param s string
|
|
|
|
--- @return string
|
2023-04-15 14:40:48 -07:00
|
|
|
local function help_to_link(s)
|
|
|
|
return vim.fn.substitute(s, [[\v:h%[elp] ([^|][^"\r\n ]+)]], [[:help |\1|]], [[g]])
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- Format a message for a specific report item.
|
|
|
|
---
|
|
|
|
--- @param status string
|
|
|
|
--- @param msg string
|
|
|
|
--- @param ... string|string[] Optional advice
|
|
|
|
--- @return string
|
2023-04-15 14:40:48 -07:00
|
|
|
local function format_report_message(status, msg, ...)
|
|
|
|
local output = '- ' .. status
|
|
|
|
if status ~= '' then
|
|
|
|
output = output .. ' '
|
|
|
|
end
|
|
|
|
|
|
|
|
output = output .. indent_after_line1(msg, 2)
|
|
|
|
|
|
|
|
local varargs = ...
|
|
|
|
|
|
|
|
-- Optional parameters
|
|
|
|
if varargs then
|
|
|
|
if type(varargs) == 'string' then
|
|
|
|
varargs = { varargs }
|
|
|
|
end
|
|
|
|
|
|
|
|
output = output .. '\n - ADVICE:'
|
|
|
|
|
|
|
|
-- Report each suggestion
|
|
|
|
for _, v in ipairs(varargs) do
|
|
|
|
if v then
|
|
|
|
output = output .. '\n - ' .. indent_after_line1(v, 6)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return help_to_link(output)
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- @param output string
|
2023-04-15 14:40:48 -07:00
|
|
|
local function collect_output(output)
|
|
|
|
vim.list_extend(s_output, vim.split(output, '\n'))
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- Starts a new report.
|
|
|
|
---
|
|
|
|
--- @param name string
|
2023-04-15 14:40:48 -07:00
|
|
|
function M.start(name)
|
|
|
|
local input = string.format('\n%s ~', name)
|
|
|
|
collect_output(input)
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- Reports a message in the current section.
|
|
|
|
---
|
|
|
|
--- @param msg string
|
2023-04-15 14:40:48 -07:00
|
|
|
function M.info(msg)
|
|
|
|
local input = format_report_message('', msg)
|
|
|
|
collect_output(input)
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- Reports a successful healthcheck.
|
|
|
|
---
|
|
|
|
--- @param msg string
|
2023-04-15 14:40:48 -07:00
|
|
|
function M.ok(msg)
|
|
|
|
local input = format_report_message('OK', msg)
|
|
|
|
collect_output(input)
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- Reports a health warning.
|
|
|
|
---
|
|
|
|
--- @param msg string
|
|
|
|
--- @param ... string|string[] Optional advice
|
2023-04-15 14:40:48 -07:00
|
|
|
function M.warn(msg, ...)
|
|
|
|
local input = format_report_message('WARNING', msg, ...)
|
|
|
|
collect_output(input)
|
2022-05-31 11:10:18 -07:00
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- Reports a failed healthcheck.
|
|
|
|
---
|
|
|
|
--- @param msg string
|
|
|
|
--- @param ... string|string[] Optional advice
|
2023-04-15 14:40:48 -07:00
|
|
|
function M.error(msg, ...)
|
|
|
|
local input = format_report_message('ERROR', msg, ...)
|
|
|
|
collect_output(input)
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- @param type string
|
2023-04-15 14:40:48 -07:00
|
|
|
local function deprecate(type)
|
|
|
|
local before = string.format('vim.health.report_%s()', type)
|
|
|
|
local after = string.format('vim.health.%s()', type)
|
|
|
|
local message = vim.deprecate(before, after, '0.11')
|
|
|
|
if message then
|
|
|
|
M.warn(message)
|
|
|
|
end
|
|
|
|
vim.cmd.redraw()
|
|
|
|
vim.print('Running healthchecks...')
|
|
|
|
end
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
--- @deprecated
|
|
|
|
--- @param name string
|
2023-04-15 14:40:48 -07:00
|
|
|
function M.report_start(name)
|
|
|
|
deprecate('start')
|
|
|
|
M.start(name)
|
|
|
|
end
|
2023-12-13 06:04:24 -07:00
|
|
|
|
|
|
|
--- @deprecated
|
|
|
|
--- @param msg string
|
2023-04-15 14:40:48 -07:00
|
|
|
function M.report_info(msg)
|
|
|
|
deprecate('info')
|
|
|
|
M.info(msg)
|
|
|
|
end
|
2023-12-13 06:04:24 -07:00
|
|
|
|
|
|
|
--- @deprecated
|
|
|
|
--- @param msg string
|
2023-04-15 14:40:48 -07:00
|
|
|
function M.report_ok(msg)
|
|
|
|
deprecate('ok')
|
|
|
|
M.ok(msg)
|
|
|
|
end
|
2023-12-13 06:04:24 -07:00
|
|
|
|
|
|
|
--- @deprecated
|
|
|
|
--- @param msg string
|
2023-04-15 14:40:48 -07:00
|
|
|
function M.report_warn(msg, ...)
|
|
|
|
deprecate('warn')
|
|
|
|
M.warn(msg, ...)
|
|
|
|
end
|
2023-12-13 06:04:24 -07:00
|
|
|
|
|
|
|
--- @deprecated
|
|
|
|
--- @param msg string
|
2022-05-31 11:10:18 -07:00
|
|
|
function M.report_error(msg, ...)
|
2023-04-15 14:40:48 -07:00
|
|
|
deprecate('error')
|
|
|
|
M.error(msg, ...)
|
2022-05-31 11:10:18 -07:00
|
|
|
end
|
|
|
|
|
2023-04-10 15:48:58 -07:00
|
|
|
function M.provider_disabled(provider)
|
|
|
|
local loaded_var = 'loaded_' .. provider .. '_provider'
|
|
|
|
local v = vim.g[loaded_var]
|
|
|
|
if v == 0 then
|
|
|
|
M.info('Disabled (' .. loaded_var .. '=' .. v .. ').')
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Handler for s:system() function.
|
|
|
|
local function system_handler(self, _, data, event)
|
|
|
|
if event == 'stderr' then
|
|
|
|
if self.add_stderr_to_output then
|
|
|
|
self.output = self.output .. table.concat(data, '')
|
|
|
|
else
|
|
|
|
self.stderr = self.stderr .. table.concat(data, '')
|
|
|
|
end
|
|
|
|
elseif event == 'stdout' then
|
|
|
|
self.output = self.output .. table.concat(data, '')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Attempts to construct a shell command from an args list.
|
|
|
|
-- Only for display, to help users debug a failed command.
|
|
|
|
local function shellify(cmd)
|
|
|
|
if type(cmd) ~= 'table' then
|
|
|
|
return cmd
|
|
|
|
end
|
|
|
|
local escaped = {}
|
|
|
|
for i, v in ipairs(cmd) do
|
|
|
|
if v:match('[^A-Za-z_/.-]') then
|
|
|
|
escaped[i] = vim.fn.shellescape(v)
|
|
|
|
else
|
|
|
|
escaped[i] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return table.concat(escaped, ' ')
|
|
|
|
end
|
|
|
|
|
|
|
|
function M.cmd_ok(cmd)
|
|
|
|
local out = vim.fn.system(cmd)
|
|
|
|
return vim.v.shell_error == 0, out
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Run a system command and timeout after 30 seconds.
|
|
|
|
---
|
|
|
|
--- @param cmd table List of command arguments to execute
|
2024-01-09 10:36:46 -07:00
|
|
|
--- @param args? table Optional arguments:
|
2023-04-10 15:48:58 -07:00
|
|
|
--- - stdin (string): Data to write to the job's stdin
|
|
|
|
--- - stderr (boolean): Append stderr to stdout
|
|
|
|
--- - ignore_error (boolean): If true, ignore error output
|
|
|
|
--- - timeout (number): Number of seconds to wait before timing out (default 30)
|
|
|
|
function M.system(cmd, args)
|
|
|
|
args = args or {}
|
|
|
|
local stdin = args.stdin or ''
|
|
|
|
local stderr = vim.F.if_nil(args.stderr, false)
|
|
|
|
local ignore_error = vim.F.if_nil(args.ignore_error, false)
|
|
|
|
|
|
|
|
local shell_error_code = 0
|
|
|
|
local opts = {
|
|
|
|
add_stderr_to_output = stderr,
|
|
|
|
output = '',
|
|
|
|
stderr = '',
|
|
|
|
on_stdout = system_handler,
|
|
|
|
on_stderr = system_handler,
|
|
|
|
on_exit = function(_, data)
|
|
|
|
shell_error_code = data
|
|
|
|
end,
|
|
|
|
}
|
|
|
|
local jobid = vim.fn.jobstart(cmd, opts)
|
|
|
|
|
|
|
|
if jobid < 1 then
|
|
|
|
local message =
|
|
|
|
string.format('Command error (job=%d): %s (in %s)', jobid, shellify(cmd), vim.loop.cwd())
|
|
|
|
error(message)
|
|
|
|
return opts.output, 1
|
|
|
|
end
|
|
|
|
|
|
|
|
if stdin:find('^%s$') then
|
|
|
|
vim.fn.chansend(jobid, stdin)
|
|
|
|
end
|
|
|
|
|
|
|
|
local res = vim.fn.jobwait({ jobid }, vim.F.if_nil(args.timeout, 30) * 1000)
|
|
|
|
if res[1] == -1 then
|
|
|
|
error('Command timed out: ' .. shellify(cmd))
|
|
|
|
vim.fn.jobstop(jobid)
|
|
|
|
elseif shell_error_code ~= 0 and not ignore_error then
|
|
|
|
local emsg = string.format(
|
|
|
|
'Command error (job=%d, exit code %d): %s (in %s)',
|
|
|
|
jobid,
|
|
|
|
shell_error_code,
|
|
|
|
shellify(cmd),
|
|
|
|
vim.loop.cwd()
|
|
|
|
)
|
|
|
|
if opts.output:find('%S') then
|
|
|
|
emsg = string.format('%s\noutput: %s', emsg, opts.output)
|
|
|
|
end
|
|
|
|
if opts.stderr:find('%S') then
|
|
|
|
emsg = string.format('%s\nstderr: %s', emsg, opts.stderr)
|
|
|
|
end
|
|
|
|
error(emsg)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- return opts.output
|
|
|
|
return vim.trim(vim.fn.system(cmd)), shell_error_code
|
|
|
|
end
|
|
|
|
|
2022-05-31 11:10:18 -07:00
|
|
|
local path2name = function(path)
|
|
|
|
if path:match('%.lua$') then
|
|
|
|
-- Lua: transform "../lua/vim/lsp/health.lua" into "vim.lsp"
|
2023-01-16 02:55:24 -07:00
|
|
|
|
|
|
|
-- Get full path, make sure all slashes are '/'
|
|
|
|
path = vim.fs.normalize(path)
|
|
|
|
|
|
|
|
-- Remove everything up to the last /lua/ folder
|
|
|
|
path = path:gsub('^.*/lua/', '')
|
|
|
|
|
|
|
|
-- Remove the filename (health.lua)
|
|
|
|
path = vim.fn.fnamemodify(path, ':h')
|
|
|
|
|
|
|
|
-- Change slashes to dots
|
|
|
|
path = path:gsub('/', '.')
|
|
|
|
|
|
|
|
return path
|
2022-05-31 11:10:18 -07:00
|
|
|
else
|
|
|
|
-- Vim: transform "../autoload/health/provider.vim" into "provider"
|
|
|
|
return vim.fn.fnamemodify(path, ':t:r')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local PATTERNS = { '/autoload/health/*.vim', '/lua/**/**/health.lua', '/lua/**/**/health/init.lua' }
|
2023-12-13 06:04:24 -07:00
|
|
|
--- :checkhealth completion function used by cmdexpand.c get_healthcheck_names()
|
2022-05-31 11:10:18 -07:00
|
|
|
M._complete = function()
|
|
|
|
local names = vim.tbl_flatten(vim.tbl_map(function(pattern)
|
|
|
|
return vim.tbl_map(path2name, vim.api.nvim_get_runtime_file(pattern, true))
|
|
|
|
end, PATTERNS))
|
|
|
|
-- Remove duplicates
|
|
|
|
local unique = {}
|
|
|
|
vim.tbl_map(function(f)
|
|
|
|
unique[f] = true
|
|
|
|
end, names)
|
2022-06-01 07:10:10 -07:00
|
|
|
-- vim.health is this file, which is not a healthcheck
|
|
|
|
unique['vim'] = nil
|
2022-05-31 11:10:18 -07:00
|
|
|
return vim.tbl_keys(unique)
|
|
|
|
end
|
|
|
|
|
2023-12-24 19:21:13 -07:00
|
|
|
--- Runs the specified healthchecks.
|
|
|
|
--- Runs all discovered healthchecks if plugin_names is empty.
|
|
|
|
---
|
|
|
|
--- @param mods string command modifiers that affect splitting a window.
|
2023-12-13 06:04:24 -07:00
|
|
|
--- @param plugin_names string glob of plugin names, split on whitespace. For example, using
|
|
|
|
--- `:checkhealth vim.* nvim` will healthcheck `vim.lsp`, `vim.treesitter`
|
|
|
|
--- and `nvim` modules.
|
2023-12-24 19:21:13 -07:00
|
|
|
function M._check(mods, plugin_names)
|
2023-04-15 14:40:48 -07:00
|
|
|
local healthchecks = plugin_names == '' and get_healthcheck('*') or get_healthcheck(plugin_names)
|
|
|
|
|
|
|
|
local emptybuf = vim.fn.bufnr('$') == 1 and vim.fn.getline(1) == '' and 1 == vim.fn.line('$')
|
2023-12-24 19:21:13 -07:00
|
|
|
|
|
|
|
-- When no command modifiers are used:
|
|
|
|
-- - If the current buffer is empty, open healthcheck directly.
|
|
|
|
-- - If not specified otherwise open healthcheck in a tab.
|
|
|
|
local buf_cmd = #mods > 0 and (mods .. ' sbuffer') or emptybuf and 'buffer' or 'tab sbuffer'
|
2023-12-24 17:30:56 -07:00
|
|
|
|
2023-04-15 14:40:48 -07:00
|
|
|
local bufnr = vim.api.nvim_create_buf(true, true)
|
2023-12-24 19:21:13 -07:00
|
|
|
vim.cmd(buf_cmd .. ' ' .. bufnr)
|
2023-04-15 14:40:48 -07:00
|
|
|
|
|
|
|
if vim.fn.bufexists('health://') == 1 then
|
|
|
|
vim.cmd.bwipe('health://')
|
|
|
|
end
|
|
|
|
vim.cmd.file('health://')
|
|
|
|
vim.cmd.setfiletype('checkhealth')
|
|
|
|
|
2023-12-13 06:04:24 -07:00
|
|
|
-- This should only happen when doing `:checkhealth vim`
|
|
|
|
if next(healthchecks) == nil then
|
2023-04-15 14:40:48 -07:00
|
|
|
vim.fn.setline(1, 'ERROR: No healthchecks found.')
|
|
|
|
return
|
|
|
|
end
|
|
|
|
vim.cmd.redraw()
|
|
|
|
vim.print('Running healthchecks...')
|
|
|
|
|
|
|
|
for name, value in vim.spairs(healthchecks) do
|
|
|
|
local func = value[1]
|
|
|
|
local type = value[2]
|
|
|
|
s_output = {}
|
|
|
|
|
|
|
|
if func == '' then
|
|
|
|
s_output = {}
|
|
|
|
M.error('No healthcheck found for "' .. name .. '" plugin.')
|
|
|
|
end
|
|
|
|
if type == 'v' then
|
2023-04-16 03:26:13 -07:00
|
|
|
vim.fn.call(func, {})
|
2023-04-15 14:40:48 -07:00
|
|
|
else
|
|
|
|
local f = assert(loadstring(func))
|
|
|
|
local ok, output = pcall(f)
|
|
|
|
if not ok then
|
|
|
|
M.error(
|
|
|
|
string.format('Failed to run healthcheck for "%s" plugin. Exception:\n%s\n', name, output)
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-- in the event the healthcheck doesn't return anything
|
|
|
|
-- (the plugin author should avoid this possibility)
|
|
|
|
if next(s_output) == nil then
|
|
|
|
s_output = {}
|
|
|
|
M.error('The healthcheck report for "' .. name .. '" plugin is empty.')
|
|
|
|
end
|
|
|
|
local header = { string.rep('=', 78), name .. ': ' .. func, '' }
|
|
|
|
-- remove empty line after header from report_start
|
|
|
|
if s_output[1] == '' then
|
2023-12-13 06:04:24 -07:00
|
|
|
local tmp = {} ---@type string[]
|
2023-04-15 14:40:48 -07:00
|
|
|
for i = 2, #s_output do
|
|
|
|
tmp[#tmp + 1] = s_output[i]
|
|
|
|
end
|
|
|
|
s_output = {}
|
|
|
|
for _, v in ipairs(tmp) do
|
|
|
|
s_output[#s_output + 1] = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
s_output[#s_output + 1] = ''
|
|
|
|
s_output = vim.list_extend(header, s_output)
|
|
|
|
vim.fn.append('$', s_output)
|
|
|
|
vim.cmd.redraw()
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Clear the 'Running healthchecks...' message.
|
|
|
|
vim.cmd.redraw()
|
|
|
|
vim.print('')
|
|
|
|
end
|
|
|
|
|
2023-04-10 15:48:58 -07:00
|
|
|
local fn_bool = function(key)
|
|
|
|
return function(...)
|
|
|
|
return vim.fn[key](...) == 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
M.executable = fn_bool('executable')
|
|
|
|
|
2022-05-31 11:10:18 -07:00
|
|
|
return M
|