aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/nvim/health.lua83
-rw-r--r--runtime/lua/provider/health.lua10
-rw-r--r--runtime/lua/vim/health.lua264
-rw-r--r--runtime/lua/vim/lsp/health.lua6
-rw-r--r--runtime/lua/vim/treesitter/health.lua6
5 files changed, 306 insertions, 63 deletions
diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua
index 6f544e9407..19303d34f9 100644
--- a/runtime/lua/nvim/health.lua
+++ b/runtime/lua/nvim/health.lua
@@ -20,7 +20,7 @@ end
local suggest_faq = 'https://github.com/neovim/neovim/wiki/Building-Neovim#optimized-builds'
local function check_runtime()
- health.report_start('Runtime')
+ health.start('Runtime')
-- Files from an old installation.
local bad_files = {
['plugin/man.vim'] = false,
@@ -37,10 +37,10 @@ local function check_runtime()
end
local ok = (bad_files_msg == '')
- local info = ok and health.report_ok or health.report_info
+ local info = ok and health.ok or health.info
info(string.format('$VIMRUNTIME: %s', vim.env.VIMRUNTIME))
if not ok then
- health.report_error(
+ health.error(
string.format(
'$VIMRUNTIME has files from an old installation (this can cause weird behavior):\n%s',
bad_files_msg
@@ -51,7 +51,7 @@ local function check_runtime()
end
local function check_config()
- health.report_start('Configuration')
+ health.start('Configuration')
local ok = true
local vimrc = (
@@ -60,7 +60,7 @@ local function check_config()
if not filereadable(vimrc) then
ok = false
local has_vim = filereadable(vim.fn.expand('~/.vimrc'))
- health.report_warn(
+ health.warn(
(-1 == vim.fn.getfsize(vimrc) and 'Missing' or 'Unreadable') .. ' user config file: ' .. vimrc,
{ has_vim and ':help nvim-from-vim' or ':help init.vim' }
)
@@ -69,12 +69,12 @@ local function check_config()
-- If $VIM is empty we don't care. Else make sure it is valid.
if not empty(vim.env.VIM) and not filereadable(vim.env.VIM .. '/runtime/doc/nvim.txt') then
ok = false
- health.report_error('$VIM is invalid: ' .. vim.env.VIM)
+ health.error('$VIM is invalid: ' .. vim.env.VIM)
end
if vim.env.NVIM_TUI_ENABLE_CURSOR_SHAPE then
ok = false
- health.report_warn('$NVIM_TUI_ENABLE_CURSOR_SHAPE is ignored in Nvim 0.2+', {
+ health.warn('$NVIM_TUI_ENABLE_CURSOR_SHAPE is ignored in Nvim 0.2+', {
"Use the 'guicursor' option to configure cursor shape. :help 'guicursor'",
'https://github.com/neovim/neovim/wiki/Following-HEAD#20170402',
})
@@ -82,7 +82,7 @@ local function check_config()
if vim.v.ctype == 'C' then
ok = false
- health.report_error(
+ health.error(
'Locale does not support UTF-8. Unicode characters may not display correctly.'
.. ('\n$LANG=%s $LC_ALL=%s $LC_CTYPE=%s'):format(
vim.env.LANG,
@@ -99,7 +99,7 @@ local function check_config()
if vim.o.paste == 1 then
ok = false
- health.report_error(
+ health.error(
"'paste' is enabled. This option is only for pasting text.\nIt should not be set in your config.",
{
'Remove `set paste` from your init.vim, if applicable.',
@@ -132,7 +132,7 @@ local function check_config()
or (not empty(shadafile) and (not filereadable(shadafile) or not filewritable(shadafile)))
then
ok = false
- health.report_error(
+ health.error(
'shada file is not '
.. ((not writeable or filereadable(shadafile)) and 'writeable' or 'readable')
.. ':\n'
@@ -141,22 +141,22 @@ local function check_config()
end
if ok then
- health.report_ok('no issues found')
+ health.ok('no issues found')
end
end
local function check_performance()
- health.report_start('Performance')
+ health.start('Performance')
-- Check buildtype
local buildtype = vim.fn.matchstr(vim.fn.execute('version'), [[\v\cbuild type:?\s*[^\n\r\t ]+]])
if empty(buildtype) then
- health.report_error('failed to get build type from :version')
+ health.error('failed to get build type from :version')
elseif vim.regex([[\v(MinSizeRel|Release|RelWithDebInfo)]]):match_str(buildtype) then
- health.report_ok(buildtype)
+ health.ok(buildtype)
else
- health.report_info(buildtype)
- health.report_warn('Non-optimized debug build. Nvim will be slower.', {
+ health.info(buildtype)
+ health.warn('Non-optimized debug build. Nvim will be slower.', {
'Install a different Nvim package, or rebuild with `CMAKE_BUILD_TYPE=RelWithDebInfo`.',
suggest_faq,
})
@@ -168,7 +168,7 @@ local function check_performance()
vim.fn.system('echo')
local elapsed_time = vim.fn.reltimefloat(vim.fn.reltime(start_time))
if elapsed_time > slow_cmd_time then
- health.report_warn(
+ health.warn(
'Slow shell invocation (took ' .. vim.fn.printf('%.2f', elapsed_time) .. ' seconds).'
)
end
@@ -176,7 +176,7 @@ end
-- Load the remote plugin manifest file and check for unregistered plugins
local function check_rplugin_manifest()
- health.report_start('Remote Plugins')
+ health.start('Remote Plugins')
local existing_rplugins = {}
for _, item in ipairs(vim.fn['remote#host#PluginsForHost']('python')) do
@@ -218,7 +218,7 @@ local function check_rplugin_manifest()
require_update = true
end
- health.report_warn(msg)
+ health.warn(msg)
end
break
@@ -231,9 +231,9 @@ local function check_rplugin_manifest()
end
if require_update then
- health.report_warn('Out of date', { 'Run `:UpdateRemotePlugins`' })
+ health.warn('Out of date', { 'Run `:UpdateRemotePlugins`' })
else
- health.report_ok('Up to date')
+ health.ok('Up to date')
end
end
@@ -247,21 +247,21 @@ local function check_tmux()
local out = vim.fn.system(vim.fn.split(cmd))
local val = vim.fn.substitute(out, [[\v(\s|\r|\n)]], '', 'g')
if shell_error() then
- health.report_error('command failed: ' .. cmd .. '\n' .. out)
+ health.error('command failed: ' .. cmd .. '\n' .. out)
return 'error'
elseif empty(val) then
cmd = 'tmux show-option -qvgs ' .. option -- try session scope
out = vim.fn.system(vim.fn.split(cmd))
val = vim.fn.substitute(out, [[\v(\s|\r|\n)]], '', 'g')
if shell_error() then
- health.report_error('command failed: ' .. cmd .. '\n' .. out)
+ health.error('command failed: ' .. cmd .. '\n' .. out)
return 'error'
end
end
return val
end
- health.report_start('tmux')
+ health.start('tmux')
-- check escape-time
local suggestions =
@@ -269,14 +269,11 @@ local function check_tmux()
local tmux_esc_time = get_tmux_option('escape-time')
if tmux_esc_time ~= 'error' then
if empty(tmux_esc_time) then
- health.report_error('`escape-time` is not set', suggestions)
+ health.error('`escape-time` is not set', suggestions)
elseif tonumber(tmux_esc_time) > 300 then
- health.report_error(
- '`escape-time` (' .. tmux_esc_time .. ') is higher than 300ms',
- suggestions
- )
+ health.error('`escape-time` (' .. tmux_esc_time .. ') is higher than 300ms', suggestions)
else
- health.report_ok('escape-time: ' .. tmux_esc_time)
+ health.ok('escape-time: ' .. tmux_esc_time)
end
end
@@ -284,17 +281,17 @@ local function check_tmux()
local tmux_focus_events = get_tmux_option('focus-events')
if tmux_focus_events ~= 'error' then
if empty(tmux_focus_events) or tmux_focus_events ~= 'on' then
- health.report_warn(
+ health.warn(
"`focus-events` is not enabled. |'autoread'| may not work.",
{ '(tmux 1.9+ only) Set `focus-events` in ~/.tmux.conf:\nset-option -g focus-events on' }
)
else
- health.report_ok('focus-events: ' .. tmux_focus_events)
+ health.ok('focus-events: ' .. tmux_focus_events)
end
end
-- check default-terminal and $TERM
- health.report_info('$TERM: ' .. vim.env.TERM)
+ health.info('$TERM: ' .. vim.env.TERM)
local cmd = 'tmux show-option -qvg default-terminal'
local out = vim.fn.system(vim.fn.split(cmd))
local tmux_default_term = vim.fn.substitute(out, [[\v(\s|\r|\n)]], '', 'g')
@@ -305,15 +302,15 @@ local function check_tmux()
end
if shell_error() then
- health.report_error('command failed: ' .. cmd .. '\n' .. out)
+ health.error('command failed: ' .. cmd .. '\n' .. out)
elseif tmux_default_term ~= vim.env.TERM then
- health.report_info('default-terminal: ' .. tmux_default_term)
- health.report_error(
+ health.info('default-terminal: ' .. tmux_default_term)
+ health.error(
'$TERM differs from the tmux `default-terminal` setting. Colors might look wrong.',
{ '$TERM may have been set by some rc (.bashrc, .zshrc, ...).' }
)
elseif not vim.regex([[\v(tmux-256color|screen-256color)]]):match_str(vim.env.TERM) then
- health.report_error(
+ health.error(
'$TERM should be "screen-256color" or "tmux-256color" in tmux. Colors might look wrong.',
{
'Set default-terminal in ~/.tmux.conf:\nset-option -g default-terminal "screen-256color"',
@@ -333,7 +330,7 @@ local function check_tmux()
has_rgb = info:find(' Tc: (flag) true', 1, true) or info:find(' RGB: (flag) true', 1, true)
end
if not has_rgb then
- health.report_warn(
+ health.warn(
"Neither Tc nor RGB capability set. True colors are disabled. |'termguicolors'| won't work properly.",
{
"Put this in your ~/.tmux.conf and replace XXX by your $TERM outside of tmux:\nset-option -sa terminal-features ',XXX:RGB'",
@@ -349,7 +346,7 @@ local function check_terminal()
return
end
- health.report_start('terminal')
+ health.start('terminal')
local cmd = 'infocmp -L'
local out = vim.fn.system(vim.fn.split(cmd))
local kbs_entry = vim.fn.matchstr(out, 'key_backspace=[^,[:space:]]*')
@@ -367,16 +364,16 @@ local function check_terminal()
)
)
then
- health.report_error('command failed: ' .. cmd .. '\n' .. out)
+ health.error('command failed: ' .. cmd .. '\n' .. out)
else
- health.report_info(
+ health.info(
vim.fn.printf(
'key_backspace (kbs) terminfo entry: `%s`',
(empty(kbs_entry) and '? (not found)' or kbs_entry)
)
)
- health.report_info(
+ health.info(
vim.fn.printf(
'key_dc (kdch1) terminfo entry: `%s`',
(empty(kbs_entry) and '? (not found)' or kdch1_entry)
@@ -392,7 +389,7 @@ local function check_terminal()
'SSH_TTY',
}) do
if vim.env[env_var] then
- health.report_info(vim.fn.printf('$%s="%s"', env_var, vim.env[env_var]))
+ health.info(vim.fn.printf('$%s="%s"', env_var, vim.env[env_var]))
end
end
end
diff --git a/runtime/lua/provider/health.lua b/runtime/lua/provider/health.lua
index de0729ab6b..1c882de222 100644
--- a/runtime/lua/provider/health.lua
+++ b/runtime/lua/provider/health.lua
@@ -1,10 +1,10 @@
local M = {}
-local start = vim.health.report_start
-local ok = vim.health.report_ok
-local info = vim.health.report_info
-local warn = vim.health.report_warn
-local error = vim.health.report_error
+local start = vim.health.start
+local ok = vim.health.ok
+local info = vim.health.info
+local warn = vim.health.warn
+local error = vim.health.error
local iswin = vim.loop.os_uname().sysname == 'Windows_NT'
local shell_error_code = 0
diff --git a/runtime/lua/vim/health.lua b/runtime/lua/vim/health.lua
index 044880e076..04f8f9695b 100644
--- a/runtime/lua/vim/health.lua
+++ b/runtime/lua/vim/health.lua
@@ -1,23 +1,196 @@
local M = {}
-function M.report_start(msg)
- vim.fn['health#report_start'](msg)
+local s_output = {}
+
+-- From a path return a list [{name}, {func}, {type}] representing a healthcheck
+local function filepath_to_healthcheck(path)
+ path = vim.fs.normalize(path)
+ local name
+ local func
+ local filetype
+ 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
+ name = vim.fs.dirname(subpath)
+ else
+ -- */health/init.lua
+ name = vim.fs.dirname(vim.fs.dirname(subpath))
+ end
+ name = name:gsub('/', '.')
+
+ func = 'require("' .. name .. '.health").check()'
+ filetype = 'l'
+ end
+ return { name, func, filetype }
end
-function M.report_info(msg)
- vim.fn['health#report_info'](msg)
+-- Returns { {name, func, type}, ... } representing healthchecks
+local function get_healthcheck_list(plugin_names)
+ local healthchecks = {}
+ plugin_names = vim.split(plugin_names, ' ')
+ for _, p in pairs(plugin_names) do
+ -- 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
+ local unique_paths = {}
+ 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
end
-function M.report_ok(msg)
- vim.fn['health#report_ok'](msg)
+-- Returns {name: [func, type], ..} representing healthchecks
+local function get_healthcheck(plugin_names)
+ local health_list = get_healthcheck_list(plugin_names)
+ local healthchecks = {}
+ for _, c in pairs(health_list) do
+ if c[1] ~= 'vim' then
+ healthchecks[c[1]] = { c[2], c[3] }
+ end
+ end
+
+ return healthchecks
end
-function M.report_warn(msg, ...)
- vim.fn['health#report_warn'](msg, ...)
+-- Indents lines *except* line 1 of a string if it contains newlines.
+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
+
+-- Changes ':h clipboard' to ':help |clipboard|'.
+local function help_to_link(s)
+ return vim.fn.substitute(s, [[\v:h%[elp] ([^|][^"\r\n ]+)]], [[:help |\1|]], [[g]])
+end
+
+-- Format a message for a specific report item.
+-- Variable args: Optional advice (string or list)
+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
+
+local function collect_output(output)
+ vim.list_extend(s_output, vim.split(output, '\n'))
+end
+
+-- Starts a new report.
+function M.start(name)
+ local input = string.format('\n%s ~', name)
+ collect_output(input)
+end
+
+-- Reports a message in the current section.
+function M.info(msg)
+ local input = format_report_message('', msg)
+ collect_output(input)
+end
+
+-- Reports a successful healthcheck.
+function M.ok(msg)
+ local input = format_report_message('OK', msg)
+ collect_output(input)
+end
+
+-- Reports a health warning.
+-- ...: Optional advice (string or table)
+function M.warn(msg, ...)
+ local input = format_report_message('WARNING', msg, ...)
+ collect_output(input)
end
+-- Reports a failed healthcheck.
+-- ...: Optional advice (string or table)
+function M.error(msg, ...)
+ local input = format_report_message('ERROR', msg, ...)
+ collect_output(input)
+end
+
+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
+
+function M.report_start(name)
+ deprecate('start')
+ M.start(name)
+end
+function M.report_info(msg)
+ deprecate('info')
+ M.info(msg)
+end
+function M.report_ok(msg)
+ deprecate('ok')
+ M.ok(msg)
+end
+function M.report_warn(msg, ...)
+ deprecate('warn')
+ M.warn(msg, ...)
+end
function M.report_error(msg, ...)
- vim.fn['health#report_error'](msg, ...)
+ deprecate('error')
+ M.error(msg, ...)
end
local path2name = function(path)
@@ -59,4 +232,77 @@ M._complete = function()
return vim.tbl_keys(unique)
end
+-- Runs the specified healthchecks.
+-- Runs all discovered healthchecks if plugin_names is empty.
+function M._check(plugin_names)
+ local healthchecks = plugin_names == '' and get_healthcheck('*') or get_healthcheck(plugin_names)
+
+ -- Create buffer and open in a tab, unless this is the default buffer when Nvim starts.
+ local emptybuf = vim.fn.bufnr('$') == 1 and vim.fn.getline(1) == '' and 1 == vim.fn.line('$')
+ local mod = emptybuf and 'buffer' or 'tab sbuffer'
+ local bufnr = vim.api.nvim_create_buf(true, true)
+ vim.cmd(mod .. ' ' .. bufnr)
+
+ if vim.fn.bufexists('health://') == 1 then
+ vim.cmd.bwipe('health://')
+ end
+ vim.cmd.file('health://')
+ vim.cmd.setfiletype('checkhealth')
+
+ if healthchecks == nil or next(healthchecks) == nil then
+ 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
+ vim.cmd.call(func, {})
+ 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
+ local tmp = {}
+ 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
+
return M
diff --git a/runtime/lua/vim/lsp/health.lua b/runtime/lua/vim/lsp/health.lua
index 987707e661..6ca468393e 100644
--- a/runtime/lua/vim/lsp/health.lua
+++ b/runtime/lua/vim/lsp/health.lua
@@ -2,8 +2,8 @@ local M = {}
--- Performs a healthcheck for LSP
function M.check()
- local report_info = vim.health.report_info
- local report_warn = vim.health.report_warn
+ local report_info = vim.health.info
+ local report_warn = vim.health.warn
local log = require('vim.lsp.log')
local current_log_level = log.get_level()
@@ -29,7 +29,7 @@ function M.check()
report_fn(string.format('Log size: %d KB', log_size / 1000))
local clients = vim.lsp.get_active_clients()
- vim.health.report_start('vim.lsp: Active Clients')
+ vim.health.start('vim.lsp: Active Clients')
if next(clients) then
for _, client in pairs(clients) do
report_info(
diff --git a/runtime/lua/vim/treesitter/health.lua b/runtime/lua/vim/treesitter/health.lua
index dabf2cdf6c..ed1161e97f 100644
--- a/runtime/lua/vim/treesitter/health.lua
+++ b/runtime/lua/vim/treesitter/health.lua
@@ -6,14 +6,14 @@ local health = require('vim.health')
function M.check()
local parsers = vim.api.nvim_get_runtime_file('parser/*', true)
- health.report_info(string.format('Nvim runtime ABI version: %d', ts.language_version))
+ health.info(string.format('Nvim runtime ABI version: %d', ts.language_version))
for _, parser in pairs(parsers) do
local parsername = vim.fn.fnamemodify(parser, ':t:r')
local is_loadable, err_or_nil = pcall(ts.language.add, parsername)
if not is_loadable then
- health.report_error(
+ health.error(
string.format(
'Parser "%s" failed to load (path: %s): %s',
parsername,
@@ -23,7 +23,7 @@ function M.check()
)
else
local lang = ts.language.inspect(parsername)
- health.report_ok(
+ health.ok(
string.format('Parser: %-10s ABI: %d, path: %s', parsername, lang._abi_version, parser)
)
end