aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authordundargoc <gocdundar@gmail.com>2024-05-18 18:35:26 +0200
committerdundargoc <33953936+dundargoc@users.noreply.github.com>2024-05-19 11:46:34 +0200
commit0f4f7d32ce5d6d3b751b0b01455770f3b72531b9 (patch)
tree44341b33654b2361319c799de28a40bd06bb3fdf /runtime/lua/vim
parent63e3a63d2fcd72c40ed2b4128a232c0931ef21cf (diff)
downloadrneovim-0f4f7d32ce5d6d3b751b0b01455770f3b72531b9.tar.gz
rneovim-0f4f7d32ce5d6d3b751b0b01455770f3b72531b9.tar.bz2
rneovim-0f4f7d32ce5d6d3b751b0b01455770f3b72531b9.zip
refactor!: remove `nvim` and `provider` module for checkhealth
The namespacing for healthchecks for neovim modules is inconsistent and confusing. The completion for `:checkhealth` with `--clean` gives ``` nvim provider.clipboard provider.node provider.perl provider.python provider.ruby vim.lsp vim.treesitter ``` There are now three top-level module names for nvim: `nvim`, `provider` and `vim` with no signs of stopping. The `nvim` name is especially confusing as it does not contain all neovim checkhealths, which makes it almost a decoy healthcheck. The confusion only worsens if you add plugins to the mix: ``` lazy mason nvim nvim-treesitter provider.clipboard provider.node provider.perl provider.python provider.ruby telescope vim.lsp vim.treesitter ``` Another problem with the current approach is that it's not easy to run nvim-only healthchecks since they don't share the same namespace. The current approach would be to run `:che nvim vim.* provider.*` and would also require the user to know these are the neovim modules. Instead, use this alternative structure: ``` vim.health vim.lsp vim.provider.clipboard vim.provider.node vim.provider.perl vim.provider.python vim.provider.ruby vim.treesitter ``` and ``` lazy mason nvim-treesitter telescope vim.health vim.lsp vim.provider.clipboard vim.provider.node vim.provider.perl vim.provider.python vim.provider.ruby vim.treesitter ``` Now, the entries are properly sorted and running nvim-only healthchecks requires running only `:che vim.*`.
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/health/health.lua409
-rw-r--r--runtime/lua/vim/provider/clipboard/health.lua39
-rw-r--r--runtime/lua/vim/provider/node/health.lua109
-rw-r--r--runtime/lua/vim/provider/perl/health.lua90
-rw-r--r--runtime/lua/vim/provider/python/health.lua499
-rw-r--r--runtime/lua/vim/provider/ruby/health.lua69
6 files changed, 1215 insertions, 0 deletions
diff --git a/runtime/lua/vim/health/health.lua b/runtime/lua/vim/health/health.lua
new file mode 100644
index 0000000000..5bc03199ee
--- /dev/null
+++ b/runtime/lua/vim/health/health.lua
@@ -0,0 +1,409 @@
+local M = {}
+local health = require('vim.health')
+
+local shell_error = function()
+ return vim.v.shell_error ~= 0
+end
+
+local suggest_faq = 'https://github.com/neovim/neovim/blob/master/BUILD.md#building'
+
+local function check_runtime()
+ health.start('Runtime')
+ -- Files from an old installation.
+ local bad_files = {
+ ['plugin/health.vim'] = false,
+ ['autoload/health/nvim.vim'] = false,
+ ['autoload/health/provider.vim'] = false,
+ ['autoload/man.vim'] = false,
+ ['plugin/man.vim'] = false,
+ ['queries/help/highlights.scm'] = false,
+ ['queries/help/injections.scm'] = false,
+ ['scripts.vim'] = false,
+ ['syntax/syncolor.vim'] = false,
+ }
+ local bad_files_msg = ''
+ for k, _ in pairs(bad_files) do
+ local path = ('%s/%s'):format(vim.env.VIMRUNTIME, k)
+ if vim.uv.fs_stat(path) then
+ bad_files[k] = true
+ bad_files_msg = ('%s%s\n'):format(bad_files_msg, path)
+ end
+ end
+
+ local ok = (bad_files_msg == '')
+ local info = ok and health.ok or health.info
+ info(string.format('$VIMRUNTIME: %s', vim.env.VIMRUNTIME))
+ if not ok then
+ health.error(
+ string.format(
+ 'Found old files in $VIMRUNTIME (this can cause weird behavior):\n%s',
+ bad_files_msg
+ ),
+ { 'Delete the $VIMRUNTIME directory (or uninstall Nvim), then reinstall Nvim.' }
+ )
+ end
+end
+
+local function check_config()
+ health.start('Configuration')
+ local ok = true
+
+ local init_lua = vim.fn.stdpath('config') .. '/init.lua'
+ local init_vim = vim.fn.stdpath('config') .. '/init.vim'
+ local vimrc = vim.env.MYVIMRC and vim.fn.expand(vim.env.MYVIMRC) or init_lua
+
+ if vim.fn.filereadable(vimrc) == 0 and vim.fn.filereadable(init_vim) == 0 then
+ ok = false
+ local has_vim = vim.fn.filereadable(vim.fn.expand('~/.vimrc')) == 1
+ health.warn(
+ ('%s user config file: %s'):format(
+ -1 == vim.fn.getfsize(vimrc) and 'Missing' or 'Unreadable',
+ vimrc
+ ),
+ { has_vim and ':help nvim-from-vim' or ':help config' }
+ )
+ end
+
+ -- If $VIM is empty we don't care. Else make sure it is valid.
+ if vim.env.VIM and vim.fn.filereadable(vim.env.VIM .. '/runtime/doc/nvim.txt') == 0 then
+ ok = false
+ health.error('$VIM is invalid: ' .. vim.env.VIM)
+ end
+
+ if vim.env.NVIM_TUI_ENABLE_CURSOR_SHAPE then
+ ok = false
+ 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',
+ })
+ end
+
+ if vim.v.ctype == 'C' then
+ ok = false
+ 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,
+ vim.env.LC_ALL,
+ vim.env.LC_CTYPE
+ ),
+ {
+ 'If using tmux, try the -u option.',
+ 'Ensure that your terminal/shell/tmux/etc inherits the environment, or set $LANG explicitly.',
+ 'Configure your system locale.',
+ }
+ )
+ end
+
+ if vim.o.paste == 1 then
+ ok = false
+ 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.',
+ 'Check `:verbose set paste?` to see if a plugin or script set the option.',
+ }
+ )
+ end
+
+ local writeable = true
+ local shadaopt = vim.fn.split(vim.o.shada, ',')
+ local shadafile = (
+ vim.o.shada == '' and vim.o.shada
+ or vim.fn.substitute(vim.fn.matchstr(shadaopt[#shadaopt], '^n.\\+'), '^n', '', '')
+ )
+ shadafile = (
+ vim.o.shadafile == ''
+ and (shadafile == '' and vim.fn.stdpath('state') .. '/shada/main.shada' or vim.fn.expand(
+ shadafile
+ ))
+ or (vim.o.shadafile == 'NONE' and '' or vim.o.shadafile)
+ )
+ if shadafile ~= '' and vim.fn.glob(shadafile) == '' then
+ -- Since this may be the first time Nvim has been run, try to create a shada file.
+ if not pcall(vim.cmd.wshada) then
+ writeable = false
+ end
+ end
+ if
+ not writeable
+ or (
+ shadafile ~= ''
+ and (vim.fn.filereadable(shadafile) == 0 or vim.fn.filewritable(shadafile) ~= 1)
+ )
+ then
+ ok = false
+ health.error(
+ 'shada file is not '
+ .. ((not writeable or vim.fn.filereadable(shadafile) == 1) and 'writeable' or 'readable')
+ .. ':\n'
+ .. shadafile
+ )
+ end
+
+ if ok then
+ health.ok('no issues found')
+ end
+end
+
+local function check_performance()
+ health.start('Performance')
+
+ -- Check buildtype
+ local buildtype = vim.fn.matchstr(vim.fn.execute('version'), [[\v\cbuild type:?\s*[^\n\r\t ]+]])
+ if buildtype == '' then
+ health.error('failed to get build type from :version')
+ elseif vim.regex([[\v(MinSizeRel|Release|RelWithDebInfo)]]):match_str(buildtype) then
+ health.ok(buildtype)
+ else
+ 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,
+ })
+ end
+
+ -- check for slow shell invocation
+ local slow_cmd_time = 1.5
+ local start_time = vim.fn.reltime()
+ vim.fn.system('echo')
+ local elapsed_time = vim.fn.reltimefloat(vim.fn.reltime(start_time))
+ if elapsed_time > slow_cmd_time then
+ health.warn(
+ 'Slow shell invocation (took ' .. vim.fn.printf('%.2f', elapsed_time) .. ' seconds).'
+ )
+ end
+end
+
+-- Load the remote plugin manifest file and check for unregistered plugins
+local function check_rplugin_manifest()
+ health.start('Remote Plugins')
+
+ local existing_rplugins = {}
+ for _, item in ipairs(vim.fn['remote#host#PluginsForHost']('python3')) do
+ existing_rplugins[item.path] = 'python3'
+ end
+
+ local require_update = false
+ local handle_path = function(path)
+ local python_glob = vim.fn.glob(path .. '/rplugin/python*', true, true)
+ if vim.tbl_isempty(python_glob) then
+ return
+ end
+
+ local python_dir = python_glob[1]
+ local python_version = vim.fs.basename(python_dir)
+
+ local scripts = vim.fn.glob(python_dir .. '/*.py', true, true)
+ vim.list_extend(scripts, vim.fn.glob(python_dir .. '/*/__init__.py', true, true))
+
+ for _, script in ipairs(scripts) do
+ local contents = vim.fn.join(vim.fn.readfile(script))
+ if vim.regex([[\<\%(from\|import\)\s\+neovim\>]]):match_str(contents) then
+ if vim.regex([[[\/]__init__\.py$]]):match_str(script) then
+ script = vim.fn.tr(vim.fn.fnamemodify(script, ':h'), '\\', '/')
+ end
+ if not existing_rplugins[script] then
+ local msg = vim.fn.printf('"%s" is not registered.', vim.fs.basename(path))
+ if python_version == 'pythonx' then
+ if vim.fn.has('python3') == 0 then
+ msg = msg .. ' (python3 not available)'
+ end
+ elseif vim.fn.has(python_version) == 0 then
+ msg = msg .. vim.fn.printf(' (%s not available)', python_version)
+ else
+ require_update = true
+ end
+
+ health.warn(msg)
+ end
+
+ break
+ end
+ end
+ end
+
+ for _, path in ipairs(vim.fn.map(vim.split(vim.o.runtimepath, ','), 'resolve(v:val)')) do
+ handle_path(path)
+ end
+
+ if require_update then
+ health.warn('Out of date', { 'Run `:UpdateRemotePlugins`' })
+ else
+ health.ok('Up to date')
+ end
+end
+
+local function check_tmux()
+ if not vim.env.TMUX or vim.fn.executable('tmux') == 0 then
+ return
+ end
+
+ local get_tmux_option = function(option)
+ local cmd = 'tmux show-option -qvg ' .. option -- try global scope
+ 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.error('command failed: ' .. cmd .. '\n' .. out)
+ return 'error'
+ elseif 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.error('command failed: ' .. cmd .. '\n' .. out)
+ return 'error'
+ end
+ end
+ return val
+ end
+
+ health.start('tmux')
+
+ -- check escape-time
+ local suggestions =
+ { 'set escape-time in ~/.tmux.conf:\nset-option -sg escape-time 10', suggest_faq }
+ local tmux_esc_time = get_tmux_option('escape-time')
+ if tmux_esc_time ~= 'error' then
+ if tmux_esc_time == '' then
+ health.error('`escape-time` is not set', suggestions)
+ elseif tonumber(tmux_esc_time) > 300 then
+ health.error('`escape-time` (' .. tmux_esc_time .. ') is higher than 300ms', suggestions)
+ else
+ health.ok('escape-time: ' .. tmux_esc_time)
+ end
+ end
+
+ -- check focus-events
+ local tmux_focus_events = get_tmux_option('focus-events')
+ if tmux_focus_events ~= 'error' then
+ if tmux_focus_events == '' or tmux_focus_events ~= 'on' then
+ 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.ok('focus-events: ' .. tmux_focus_events)
+ end
+ end
+
+ -- check default-terminal and $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')
+ if tmux_default_term == '' then
+ cmd = 'tmux show-option -qvgs default-terminal'
+ out = vim.fn.system(vim.fn.split(cmd))
+ tmux_default_term = vim.fn.substitute(out, [[\v(\s|\r|\n)]], '', 'g')
+ end
+
+ if shell_error() then
+ health.error('command failed: ' .. cmd .. '\n' .. out)
+ elseif tmux_default_term ~= vim.env.TERM then
+ 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.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"',
+ suggest_faq,
+ }
+ )
+ end
+
+ -- check for RGB capabilities
+ local info = vim.fn.system({ 'tmux', 'show-messages', '-T' })
+ local has_setrgbb = vim.fn.stridx(info, ' setrgbb: (string)') ~= -1
+ local has_setrgbf = vim.fn.stridx(info, ' setrgbf: (string)') ~= -1
+ if not has_setrgbb or not has_setrgbf then
+ health.warn(
+ "True color support could not be detected. |'termguicolors'| won't work properly.",
+ {
+ "Add the following to your tmux configuration file, replacing XXX by the value of $TERM outside of tmux:\nset-option -a terminal-features 'XXX:RGB'",
+ "For older tmux versions use this instead:\nset-option -a terminal-overrides 'XXX:Tc'",
+ }
+ )
+ end
+end
+
+local function check_terminal()
+ if vim.fn.executable('infocmp') == 0 then
+ return
+ end
+
+ 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:]]*')
+ local kdch1_entry = vim.fn.matchstr(out, 'key_dc=[^,[:space:]]*')
+
+ if
+ shell_error()
+ and (
+ vim.fn.has('win32') == 0
+ or vim.fn.matchstr(
+ out,
+ [[infocmp: couldn't open terminfo file .\+\%(conemu\|vtpcon\|win32con\)]]
+ )
+ == ''
+ )
+ then
+ health.error('command failed: ' .. cmd .. '\n' .. out)
+ else
+ health.info(
+ vim.fn.printf(
+ 'key_backspace (kbs) terminfo entry: `%s`',
+ (kbs_entry == '' and '? (not found)' or kbs_entry)
+ )
+ )
+
+ health.info(
+ vim.fn.printf(
+ 'key_dc (kdch1) terminfo entry: `%s`',
+ (kbs_entry == '' and '? (not found)' or kdch1_entry)
+ )
+ )
+ end
+
+ for _, env_var in ipairs({
+ 'XTERM_VERSION',
+ 'VTE_VERSION',
+ 'TERM_PROGRAM',
+ 'COLORTERM',
+ 'SSH_TTY',
+ }) do
+ if vim.env[env_var] then
+ health.info(vim.fn.printf('$%s="%s"', env_var, vim.env[env_var]))
+ end
+ end
+end
+
+local function check_external_tools()
+ health.start('External Tools')
+
+ if vim.fn.executable('rg') == 1 then
+ local rg = vim.fn.exepath('rg')
+ local cmd = 'rg -V'
+ local out = vim.fn.system(vim.fn.split(cmd))
+ health.ok(('%s (%s)'):format(vim.trim(out), rg))
+ else
+ health.warn('ripgrep not available')
+ end
+end
+
+function M.check()
+ check_config()
+ check_runtime()
+ check_performance()
+ check_rplugin_manifest()
+ check_terminal()
+ check_tmux()
+ check_external_tools()
+end
+
+return M
diff --git a/runtime/lua/vim/provider/clipboard/health.lua b/runtime/lua/vim/provider/clipboard/health.lua
new file mode 100644
index 0000000000..e44f7d32cc
--- /dev/null
+++ b/runtime/lua/vim/provider/clipboard/health.lua
@@ -0,0 +1,39 @@
+local health = vim.health
+
+local M = {}
+
+function M.check()
+ health.start('Clipboard (optional)')
+
+ if
+ os.getenv('TMUX')
+ and vim.fn.executable('tmux') == 1
+ and vim.fn.executable('pbpaste') == 1
+ and not health.cmd_ok('pbpaste')
+ then
+ local tmux_version = string.match(vim.fn.system('tmux -V'), '%d+%.%d+')
+ local advice = {
+ 'Install tmux 2.6+. https://superuser.com/q/231130',
+ 'or use tmux with reattach-to-user-namespace. https://superuser.com/a/413233',
+ }
+ health.error('pbcopy does not work with tmux version: ' .. tmux_version, advice)
+ end
+
+ local clipboard_tool = vim.fn['provider#clipboard#Executable']()
+ if vim.g.clipboard ~= nil and clipboard_tool == '' then
+ local error_message = vim.fn['provider#clipboard#Error']()
+ health.error(
+ error_message,
+ "Use the example in :help g:clipboard as a template, or don't set g:clipboard at all."
+ )
+ elseif clipboard_tool:find('^%s*$') then
+ health.warn(
+ 'No clipboard tool found. Clipboard registers (`"+` and `"*`) will not work.',
+ ':help clipboard'
+ )
+ else
+ health.ok('Clipboard tool found: ' .. clipboard_tool)
+ end
+end
+
+return M
diff --git a/runtime/lua/vim/provider/node/health.lua b/runtime/lua/vim/provider/node/health.lua
new file mode 100644
index 0000000000..471c625388
--- /dev/null
+++ b/runtime/lua/vim/provider/node/health.lua
@@ -0,0 +1,109 @@
+local health = vim.health
+local iswin = vim.loop.os_uname().sysname == 'Windows_NT'
+
+local M = {}
+
+function M.check()
+ health.start('Node.js provider (optional)')
+
+ if health.provider_disabled('node') then
+ return
+ end
+
+ if
+ vim.fn.executable('node') == 0
+ or (
+ vim.fn.executable('npm') == 0
+ and vim.fn.executable('yarn') == 0
+ and vim.fn.executable('pnpm') == 0
+ )
+ then
+ health.warn(
+ '`node` and `npm` (or `yarn`, `pnpm`) must be in $PATH.',
+ 'Install Node.js and verify that `node` and `npm` (or `yarn`, `pnpm`) commands work.'
+ )
+ return
+ end
+
+ -- local node_v = vim.fn.split(system({'node', '-v'}), "\n")[1] or ''
+ local ok, node_v = health.cmd_ok({ 'node', '-v' })
+ health.info('Node.js: ' .. node_v)
+ if not ok or vim.version.lt(node_v, '6.0.0') then
+ health.warn('Nvim node.js host does not support Node ' .. node_v)
+ -- Skip further checks, they are nonsense if nodejs is too old.
+ return
+ end
+ if vim.fn['provider#node#can_inspect']() == 0 then
+ health.warn(
+ 'node.js on this system does not support --inspect-brk so $NVIM_NODE_HOST_DEBUG is ignored.'
+ )
+ end
+
+ local node_detect_table = vim.fn['provider#node#Detect']()
+ local host = node_detect_table[1]
+ if host:find('^%s*$') then
+ health.warn('Missing "neovim" npm (or yarn, pnpm) package.', {
+ 'Run in shell: npm install -g neovim',
+ 'Run in shell (if you use yarn): yarn global add neovim',
+ 'Run in shell (if you use pnpm): pnpm install -g neovim',
+ 'You may disable this provider (and warning) by adding `let g:loaded_node_provider = 0` to your init.vim',
+ })
+ return
+ end
+ health.info('Nvim node.js host: ' .. host)
+
+ local manager = 'npm'
+ if vim.fn.executable('yarn') == 1 then
+ manager = 'yarn'
+ elseif vim.fn.executable('pnpm') == 1 then
+ manager = 'pnpm'
+ end
+
+ local latest_npm_cmd = (
+ iswin and 'cmd /c ' .. manager .. ' info neovim --json' or manager .. ' info neovim --json'
+ )
+ local latest_npm
+ ok, latest_npm = health.cmd_ok(vim.split(latest_npm_cmd, ' '))
+ if not ok or latest_npm:find('^%s$') then
+ health.error(
+ 'Failed to run: ' .. latest_npm_cmd,
+ { "Make sure you're connected to the internet.", 'Are you behind a firewall or proxy?' }
+ )
+ return
+ end
+
+ local pcall_ok, pkg_data = pcall(vim.json.decode, latest_npm)
+ if not pcall_ok then
+ return 'error: ' .. latest_npm
+ end
+ local latest_npm_subtable = pkg_data['dist-tags'] or {}
+ latest_npm = latest_npm_subtable['latest'] or 'unable to parse'
+
+ local current_npm_cmd = { 'node', host, '--version' }
+ local current_npm
+ ok, current_npm = health.cmd_ok(current_npm_cmd)
+ if not ok then
+ health.error(
+ 'Failed to run: ' .. table.concat(current_npm_cmd, ' '),
+ { 'Report this issue with the output of: ', table.concat(current_npm_cmd, ' ') }
+ )
+ return
+ end
+
+ if latest_npm ~= 'unable to parse' and vim.version.lt(current_npm, latest_npm) then
+ local message = 'Package "neovim" is out-of-date. Installed: '
+ .. current_npm:gsub('%\n$', '')
+ .. ', latest: '
+ .. latest_npm:gsub('%\n$', '')
+
+ health.warn(message, {
+ 'Run in shell: npm install -g neovim',
+ 'Run in shell (if you use yarn): yarn global add neovim',
+ 'Run in shell (if you use pnpm): pnpm install -g neovim',
+ })
+ else
+ health.ok('Latest "neovim" npm/yarn/pnpm package is installed: ' .. current_npm)
+ end
+end
+
+return M
diff --git a/runtime/lua/vim/provider/perl/health.lua b/runtime/lua/vim/provider/perl/health.lua
new file mode 100644
index 0000000000..535093d793
--- /dev/null
+++ b/runtime/lua/vim/provider/perl/health.lua
@@ -0,0 +1,90 @@
+local health = vim.health
+
+local M = {}
+
+function M.check()
+ health.start('Perl provider (optional)')
+
+ if health.provider_disabled('perl') then
+ return
+ end
+
+ local perl_exec, perl_warnings = vim.provider.perl.detect()
+
+ if not perl_exec then
+ health.warn(assert(perl_warnings), {
+ 'See :help provider-perl for more information.',
+ 'You may disable this provider (and warning) by adding `let g:loaded_perl_provider = 0` to your init.vim',
+ })
+ health.warn('No usable perl executable found')
+ return
+ end
+
+ health.info('perl executable: ' .. perl_exec)
+
+ -- we cannot use cpanm that is on the path, as it may not be for the perl
+ -- set with g:perl_host_prog
+ local ok = health.cmd_ok({ perl_exec, '-W', '-MApp::cpanminus', '-e', '' })
+ if not ok then
+ return { perl_exec, '"App::cpanminus" module is not installed' }
+ end
+
+ local latest_cpan_cmd = {
+ perl_exec,
+ '-MApp::cpanminus::fatscript',
+ '-e',
+ 'my $app = App::cpanminus::script->new; $app->parse_options ("--info", "-q", "Neovim::Ext"); exit $app->doit',
+ }
+ local latest_cpan
+ ok, latest_cpan = health.cmd_ok(latest_cpan_cmd)
+ if not ok or latest_cpan:find('^%s*$') then
+ health.error(
+ 'Failed to run: ' .. table.concat(latest_cpan_cmd, ' '),
+ { "Make sure you're connected to the internet.", 'Are you behind a firewall or proxy?' }
+ )
+ return
+ elseif latest_cpan[1] == '!' then
+ local cpanm_errs = vim.split(latest_cpan, '!')
+ if cpanm_errs[1]:find("Can't write to ") then
+ local advice = {}
+ for i = 2, #cpanm_errs do
+ advice[#advice + 1] = cpanm_errs[i]
+ end
+
+ health.warn(cpanm_errs[1], advice)
+ -- Last line is the package info
+ latest_cpan = cpanm_errs[#cpanm_errs]
+ else
+ health.error('Unknown warning from command: ' .. latest_cpan_cmd, cpanm_errs)
+ return
+ end
+ end
+ latest_cpan = vim.fn.matchstr(latest_cpan, [[\(\.\?\d\)\+]])
+ if latest_cpan:find('^%s*$') then
+ health.error('Cannot parse version number from cpanm output: ' .. latest_cpan)
+ return
+ end
+
+ local current_cpan_cmd = { perl_exec, '-W', '-MNeovim::Ext', '-e', 'print $Neovim::Ext::VERSION' }
+ local current_cpan
+ ok, current_cpan = health.cmd_ok(current_cpan_cmd)
+ if not ok then
+ health.error(
+ 'Failed to run: ' .. table.concat(current_cpan_cmd, ' '),
+ { 'Report this issue with the output of: ', table.concat(current_cpan_cmd, ' ') }
+ )
+ return
+ end
+
+ if vim.version.lt(current_cpan, latest_cpan) then
+ local message = 'Module "Neovim::Ext" is out-of-date. Installed: '
+ .. current_cpan
+ .. ', latest: '
+ .. latest_cpan
+ health.warn(message, 'Run in shell: cpanm -n Neovim::Ext')
+ else
+ health.ok('Latest "Neovim::Ext" cpan module is installed: ' .. current_cpan)
+ end
+end
+
+return M
diff --git a/runtime/lua/vim/provider/python/health.lua b/runtime/lua/vim/provider/python/health.lua
new file mode 100644
index 0000000000..a5bd738063
--- /dev/null
+++ b/runtime/lua/vim/provider/python/health.lua
@@ -0,0 +1,499 @@
+local health = vim.health
+local iswin = vim.loop.os_uname().sysname == 'Windows_NT'
+
+local M = {}
+
+local function is(path, ty)
+ if not path then
+ return false
+ end
+ local stat = vim.loop.fs_stat(path)
+ if not stat then
+ return false
+ end
+ return stat.type == ty
+end
+
+-- Resolves Python executable path by invoking and checking `sys.executable`.
+local function python_exepath(invocation)
+ local p = vim.system({ invocation, '-c', 'import sys; sys.stdout.write(sys.executable)' }):wait()
+ assert(p.code == 0, p.stderr)
+ return vim.fs.normalize(vim.trim(p.stdout))
+end
+
+-- Check if pyenv is available and a valid pyenv root can be found, then return
+-- their respective paths. If either of those is invalid, return two empty
+-- strings, effectively ignoring pyenv.
+local function check_for_pyenv()
+ local pyenv_path = vim.fn.resolve(vim.fn.exepath('pyenv'))
+
+ if pyenv_path == '' then
+ return { '', '' }
+ end
+
+ health.info('pyenv: Path: ' .. pyenv_path)
+
+ local pyenv_root = vim.fn.resolve(os.getenv('PYENV_ROOT') or '')
+
+ if pyenv_root == '' then
+ pyenv_root = vim.fn.system({ pyenv_path, 'root' })
+ health.info('pyenv: $PYENV_ROOT is not set. Infer from `pyenv root`.')
+ end
+
+ if not is(pyenv_root, 'directory') then
+ local message = string.format(
+ 'pyenv: Root does not exist: %s. Ignoring pyenv for all following checks.',
+ pyenv_root
+ )
+ health.warn(message)
+ return { '', '' }
+ end
+
+ health.info('pyenv: Root: ' .. pyenv_root)
+
+ return { pyenv_path, pyenv_root }
+end
+
+-- Check the Python interpreter's usability.
+local function check_bin(bin)
+ if not is(bin, 'file') and (not iswin or not is(bin .. '.exe', 'file')) then
+ health.error('"' .. bin .. '" was not found.')
+ return false
+ elseif vim.fn.executable(bin) == 0 then
+ health.error('"' .. bin .. '" is not executable.')
+ return false
+ end
+ return true
+end
+
+-- Fetch the contents of a URL.
+local function download(url)
+ local has_curl = vim.fn.executable('curl') == 1
+ if has_curl and vim.fn.system({ 'curl', '-V' }):find('Protocols:.*https') then
+ local out, rc = health.system({ 'curl', '-sL', url }, { stderr = true, ignore_error = true })
+ if rc ~= 0 then
+ return 'curl error with ' .. url .. ': ' .. rc
+ else
+ return out
+ end
+ elseif vim.fn.executable('python') == 1 then
+ local script = "try:\n\
+ from urllib.request import urlopen\n\
+ except ImportError:\n\
+ from urllib2 import urlopen\n\
+ response = urlopen('" .. url .. "')\n\
+ print(response.read().decode('utf8'))\n"
+ local out, rc = health.system({ 'python', '-c', script })
+ if out == '' and rc ~= 0 then
+ return 'python urllib.request error: ' .. rc
+ else
+ return out
+ end
+ end
+
+ local message = 'missing `curl` '
+
+ if has_curl then
+ message = message .. '(with HTTPS support) '
+ end
+ message = message .. 'and `python`, cannot make web request'
+
+ return message
+end
+
+-- Get the latest Nvim Python client (pynvim) version from PyPI.
+local function latest_pypi_version()
+ local pypi_version = 'unable to get pypi response'
+ local pypi_response = download('https://pypi.python.org/pypi/pynvim/json')
+ if pypi_response ~= '' then
+ local pcall_ok, output = pcall(vim.fn.json_decode, pypi_response)
+ local pypi_data
+ if pcall_ok then
+ pypi_data = output
+ else
+ return 'error: ' .. pypi_response
+ end
+
+ local pypi_element = pypi_data['info'] or {}
+ pypi_version = pypi_element['version'] or 'unable to parse'
+ end
+ return pypi_version
+end
+
+local function is_bad_response(s)
+ local lower = s:lower()
+ return vim.startswith(lower, 'unable')
+ or vim.startswith(lower, 'error')
+ or vim.startswith(lower, 'outdated')
+end
+
+-- Get version information using the specified interpreter. The interpreter is
+-- used directly in case breaking changes were introduced since the last time
+-- Nvim's Python client was updated.
+--
+-- Returns: {
+-- {python executable version},
+-- {current nvim version},
+-- {current pypi nvim status},
+-- {installed version status}
+-- }
+local function version_info(python)
+ local pypi_version = latest_pypi_version()
+
+ local python_version, rc = health.system({
+ python,
+ '-c',
+ 'import sys; print(".".join(str(x) for x in sys.version_info[:3]))',
+ })
+
+ if rc ~= 0 or python_version == '' then
+ python_version = 'unable to parse ' .. python .. ' response'
+ end
+
+ local nvim_path
+ nvim_path, rc = health.system({
+ python,
+ '-c',
+ 'import sys; sys.path = [p for p in sys.path if p != ""]; import neovim; print(neovim.__file__)',
+ })
+ if rc ~= 0 or nvim_path == '' then
+ return { python_version, 'unable to load neovim Python module', pypi_version, nvim_path }
+ end
+
+ -- Assuming that multiple versions of a package are installed, sort them
+ -- numerically in descending order.
+ local function compare(metapath1, metapath2)
+ local a = vim.fn.matchstr(vim.fn.fnamemodify(metapath1, ':p:h:t'), [[[0-9.]\+]])
+ local b = vim.fn.matchstr(vim.fn.fnamemodify(metapath2, ':p:h:t'), [[[0-9.]\+]])
+ if a == b then
+ return 0
+ elseif a > b then
+ return 1
+ else
+ return -1
+ end
+ end
+
+ -- Try to get neovim.VERSION (added in 0.1.11dev).
+ local nvim_version
+ nvim_version, rc = health.system({
+ python,
+ '-c',
+ 'from neovim import VERSION as v; print("{}.{}.{}{}".format(v.major, v.minor, v.patch, v.prerelease))',
+ }, { stderr = true, ignore_error = true })
+ if rc ~= 0 or nvim_version == '' then
+ nvim_version = 'unable to find pynvim module version'
+ local base = vim.fs.basename(nvim_path)
+ local metas = vim.fn.glob(base .. '-*/METADATA', 1, 1)
+ vim.list_extend(metas, vim.fn.glob(base .. '-*/PKG-INFO', 1, 1))
+ vim.list_extend(metas, vim.fn.glob(base .. '.egg-info/PKG-INFO', 1, 1))
+ metas = table.sort(metas, compare)
+
+ if metas and next(metas) ~= nil then
+ for line in io.lines(metas[1]) do
+ local version = line:match('^Version: (%S+)')
+ if version then
+ nvim_version = version
+ break
+ end
+ end
+ end
+ end
+
+ local nvim_path_base = vim.fn.fnamemodify(nvim_path, [[:~:h]])
+ local version_status = 'unknown; ' .. nvim_path_base
+ if is_bad_response(nvim_version) and is_bad_response(pypi_version) then
+ if vim.version.lt(nvim_version, pypi_version) then
+ version_status = 'outdated; from ' .. nvim_path_base
+ else
+ version_status = 'up to date'
+ end
+ end
+
+ return { python_version, nvim_version, pypi_version, version_status }
+end
+
+function M.check()
+ health.start('Python 3 provider (optional)')
+
+ local pyname = 'python3' ---@type string?
+ local python_exe = ''
+ local virtual_env = os.getenv('VIRTUAL_ENV')
+ local venv = virtual_env and vim.fn.resolve(virtual_env) or ''
+ local host_prog_var = pyname .. '_host_prog'
+ local python_multiple = {}
+
+ if health.provider_disabled(pyname) then
+ return
+ end
+
+ local pyenv_table = check_for_pyenv()
+ local pyenv = pyenv_table[1]
+ local pyenv_root = pyenv_table[2]
+
+ if vim.g[host_prog_var] then
+ local message = string.format('Using: g:%s = "%s"', host_prog_var, vim.g[host_prog_var])
+ health.info(message)
+ end
+
+ local pythonx_warnings
+ pyname, pythonx_warnings = vim.provider.python.detect_by_module('neovim')
+
+ if not pyname then
+ health.warn(
+ 'No Python executable found that can `import neovim`. '
+ .. 'Using the first available executable for diagnostics.'
+ )
+ elseif vim.g[host_prog_var] then
+ python_exe = pyname
+ end
+
+ -- No Python executable could `import neovim`, or host_prog_var was used.
+ if pythonx_warnings then
+ health.warn(pythonx_warnings, {
+ 'See :help provider-python for more information.',
+ 'You may disable this provider (and warning) by adding `let g:loaded_python3_provider = 0` to your init.vim',
+ })
+ elseif pyname and pyname ~= '' and python_exe == '' then
+ if not vim.g[host_prog_var] then
+ local message = string.format(
+ '`g:%s` is not set. Searching for %s in the environment.',
+ host_prog_var,
+ pyname
+ )
+ health.info(message)
+ end
+
+ if pyenv ~= '' then
+ python_exe = health.system({ pyenv, 'which', pyname }, { stderr = true })
+ if python_exe == '' then
+ health.warn('pyenv could not find ' .. pyname .. '.')
+ end
+ end
+
+ if python_exe == '' then
+ python_exe = vim.fn.exepath(pyname)
+
+ if os.getenv('PATH') then
+ local path_sep = iswin and ';' or ':'
+ local paths = vim.split(os.getenv('PATH') or '', path_sep)
+
+ for _, path in ipairs(paths) do
+ local path_bin = vim.fs.normalize(path .. '/' .. pyname)
+ if
+ path_bin ~= vim.fs.normalize(python_exe)
+ and vim.tbl_contains(python_multiple, path_bin)
+ and vim.fn.executable(path_bin) == 1
+ then
+ python_multiple[#python_multiple + 1] = path_bin
+ end
+ end
+
+ if vim.tbl_count(python_multiple) > 0 then
+ -- This is worth noting since the user may install something
+ -- that changes $PATH, like homebrew.
+ local message = string.format(
+ 'Multiple %s executables found. Set `g:%s` to avoid surprises.',
+ pyname,
+ host_prog_var
+ )
+ health.info(message)
+ end
+
+ if python_exe:find('shims') then
+ local message = string.format('`%s` appears to be a pyenv shim.', python_exe)
+ local advice = string.format(
+ '`pyenv` is not in $PATH, your pyenv installation is broken. Set `g:%s` to avoid surprises.',
+ host_prog_var
+ )
+ health.warn(message, advice)
+ end
+ end
+ end
+ end
+
+ if python_exe ~= '' and not vim.g[host_prog_var] then
+ if
+ venv == ''
+ and pyenv ~= ''
+ and pyenv_root ~= ''
+ and vim.startswith(vim.fn.resolve(python_exe), pyenv_root .. '/')
+ then
+ local advice = string.format(
+ 'Create a virtualenv specifically for Nvim using pyenv, and set `g:%s`. This will avoid the need to install the pynvim module in each version/virtualenv.',
+ host_prog_var
+ )
+ health.warn('pyenv is not set up optimally.', advice)
+ elseif venv ~= '' then
+ local venv_root
+ if pyenv_root ~= '' then
+ venv_root = pyenv_root
+ else
+ venv_root = vim.fs.dirname(venv)
+ end
+
+ if vim.startswith(vim.fn.resolve(python_exe), venv_root .. '/') then
+ local advice = string.format(
+ 'Create a virtualenv specifically for Nvim and use `g:%s`. This will avoid the need to install the pynvim module in each virtualenv.',
+ host_prog_var
+ )
+ health.warn('Your virtualenv is not set up optimally.', advice)
+ end
+ end
+ end
+
+ if pyname and python_exe == '' and pyname ~= '' then
+ -- An error message should have already printed.
+ health.error('`' .. pyname .. '` was not found.')
+ elseif python_exe ~= '' and not check_bin(python_exe) then
+ python_exe = ''
+ end
+
+ -- Diagnostic output
+ health.info('Executable: ' .. (python_exe == '' and 'Not found' or python_exe))
+ if vim.tbl_count(python_multiple) > 0 then
+ for _, path_bin in ipairs(python_multiple) do
+ health.info('Other python executable: ' .. path_bin)
+ end
+ end
+
+ if python_exe == '' then
+ -- No Python executable can import 'neovim'. Check if any Python executable
+ -- can import 'pynvim'. If so, that Python failed to import 'neovim' as
+ -- well, which is most probably due to a failed pip upgrade:
+ -- https://github.com/neovim/neovim/wiki/Following-HEAD#20181118
+ local pynvim_exe = vim.provider.python.detect_by_module('pynvim')
+ if pynvim_exe then
+ local message = 'Detected pip upgrade failure: Python executable can import "pynvim" but not "neovim": '
+ .. pynvim_exe
+ local advice = {
+ 'Use that Python version to reinstall "pynvim" and optionally "neovim".',
+ pynvim_exe .. ' -m pip uninstall pynvim neovim',
+ pynvim_exe .. ' -m pip install pynvim',
+ pynvim_exe .. ' -m pip install neovim # only if needed by third-party software',
+ }
+ health.error(message, advice)
+ end
+ else
+ local version_info_table = version_info(python_exe)
+ local pyversion = version_info_table[1]
+ local current = version_info_table[2]
+ local latest = version_info_table[3]
+ local status = version_info_table[4]
+
+ if not vim.version.range('~3'):has(pyversion) then
+ health.warn('Unexpected Python version. This could lead to confusing error messages.')
+ end
+
+ health.info('Python version: ' .. pyversion)
+
+ if is_bad_response(status) then
+ health.info('pynvim version: ' .. current .. ' (' .. status .. ')')
+ else
+ health.info('pynvim version: ' .. current)
+ end
+
+ if is_bad_response(current) then
+ health.error(
+ 'pynvim is not installed.\nError: ' .. current,
+ 'Run in shell: ' .. python_exe .. ' -m pip install pynvim'
+ )
+ end
+
+ if is_bad_response(latest) then
+ health.warn('Could not contact PyPI to get latest version.')
+ health.error('HTTP request failed: ' .. latest)
+ elseif is_bad_response(status) then
+ health.warn('Latest pynvim is NOT installed: ' .. latest)
+ elseif not is_bad_response(current) then
+ health.ok('Latest pynvim is installed.')
+ end
+ end
+
+ health.start('Python virtualenv')
+ if not virtual_env then
+ health.ok('no $VIRTUAL_ENV')
+ return
+ end
+ local errors = {}
+ -- Keep hints as dict keys in order to discard duplicates.
+ local hints = {}
+ -- The virtualenv should contain some Python executables, and those
+ -- executables should be first both on Nvim's $PATH and the $PATH of
+ -- subshells launched from Nvim.
+ local bin_dir = iswin and 'Scripts' or 'bin'
+ local venv_bins = vim.fn.glob(string.format('%s/%s/python*', virtual_env, bin_dir), true, true)
+ venv_bins = vim.tbl_filter(function(v)
+ -- XXX: Remove irrelevant executables found in bin/.
+ return not v:match('python%-config')
+ end, venv_bins)
+ if vim.tbl_count(venv_bins) > 0 then
+ for _, venv_bin in pairs(venv_bins) do
+ venv_bin = vim.fs.normalize(venv_bin)
+ local py_bin_basename = vim.fs.basename(venv_bin)
+ local nvim_py_bin = python_exepath(vim.fn.exepath(py_bin_basename))
+ local subshell_py_bin = python_exepath(py_bin_basename)
+ if venv_bin ~= nvim_py_bin then
+ errors[#errors + 1] = '$PATH yields this '
+ .. py_bin_basename
+ .. ' executable: '
+ .. nvim_py_bin
+ local hint = '$PATH ambiguities arise if the virtualenv is not '
+ .. 'properly activated prior to launching Nvim. Close Nvim, activate the virtualenv, '
+ .. 'check that invoking Python from the command line launches the correct one, '
+ .. 'then relaunch Nvim.'
+ hints[hint] = true
+ end
+ if venv_bin ~= subshell_py_bin then
+ errors[#errors + 1] = '$PATH in subshells yields this '
+ .. py_bin_basename
+ .. ' executable: '
+ .. subshell_py_bin
+ local hint = '$PATH ambiguities in subshells typically are '
+ .. 'caused by your shell config overriding the $PATH previously set by the '
+ .. 'virtualenv. Either prevent them from doing so, or use this workaround: '
+ .. 'https://vi.stackexchange.com/a/34996'
+ hints[hint] = true
+ end
+ end
+ else
+ errors[#errors + 1] = 'no Python executables found in the virtualenv '
+ .. bin_dir
+ .. ' directory.'
+ end
+
+ local msg = '$VIRTUAL_ENV is set to: ' .. virtual_env
+ if vim.tbl_count(errors) > 0 then
+ if vim.tbl_count(venv_bins) > 0 then
+ msg = string.format(
+ '%s\nAnd its %s directory contains: %s',
+ msg,
+ bin_dir,
+ table.concat(
+ vim.tbl_map(function(v)
+ return vim.fs.basename(v)
+ end, venv_bins),
+ ', '
+ )
+ )
+ end
+ local conj = '\nBut '
+ for _, err in ipairs(errors) do
+ msg = msg .. conj .. err
+ conj = '\nAnd '
+ end
+ msg = msg .. '\nSo invoking Python may lead to unexpected results.'
+ health.warn(msg, vim.tbl_keys(hints))
+ else
+ health.info(msg)
+ health.info(
+ 'Python version: '
+ .. health.system(
+ 'python -c "import platform, sys; sys.stdout.write(platform.python_version())"'
+ )
+ )
+ health.ok('$VIRTUAL_ENV provides :!python.')
+ end
+end
+
+return M
diff --git a/runtime/lua/vim/provider/ruby/health.lua b/runtime/lua/vim/provider/ruby/health.lua
new file mode 100644
index 0000000000..31c2fe3201
--- /dev/null
+++ b/runtime/lua/vim/provider/ruby/health.lua
@@ -0,0 +1,69 @@
+local health = vim.health
+local iswin = vim.loop.os_uname().sysname == 'Windows_NT'
+
+local M = {}
+
+function M.check()
+ health.start('Ruby provider (optional)')
+
+ if health.provider_disabled('ruby') then
+ return
+ end
+
+ if vim.fn.executable('ruby') == 0 or vim.fn.executable('gem') == 0 then
+ health.warn(
+ '`ruby` and `gem` must be in $PATH.',
+ 'Install Ruby and verify that `ruby` and `gem` commands work.'
+ )
+ return
+ end
+ health.info('Ruby: ' .. health.system({ 'ruby', '-v' }))
+
+ local host, _ = vim.provider.ruby.detect()
+ if (not host) or host:find('^%s*$') then
+ health.warn('`neovim-ruby-host` not found.', {
+ 'Run `gem install neovim` to ensure the neovim RubyGem is installed.',
+ 'Run `gem environment` to ensure the gem bin directory is in $PATH.',
+ 'If you are using rvm/rbenv/chruby, try "rehashing".',
+ 'See :help g:ruby_host_prog for non-standard gem installations.',
+ 'You may disable this provider (and warning) by adding `let g:loaded_ruby_provider = 0` to your init.vim',
+ })
+ return
+ end
+ health.info('Host: ' .. host)
+
+ local latest_gem_cmd = (iswin and 'cmd /c gem list -ra "^^neovim$"' or 'gem list -ra ^neovim$')
+ local ok, latest_gem = health.cmd_ok(vim.split(latest_gem_cmd, ' '))
+ if not ok or latest_gem:find('^%s*$') then
+ health.error(
+ 'Failed to run: ' .. latest_gem_cmd,
+ { "Make sure you're connected to the internet.", 'Are you behind a firewall or proxy?' }
+ )
+ return
+ end
+ local gem_split = vim.split(latest_gem, [[neovim (\|, \|)$]])
+ latest_gem = gem_split[1] or 'not found'
+
+ local current_gem_cmd = { host, '--version' }
+ local current_gem
+ ok, current_gem = health.cmd_ok(current_gem_cmd)
+ if not ok then
+ health.error(
+ 'Failed to run: ' .. table.concat(current_gem_cmd, ' '),
+ { 'Report this issue with the output of: ', table.concat(current_gem_cmd, ' ') }
+ )
+ return
+ end
+
+ if vim.version.lt(current_gem, latest_gem) then
+ local message = 'Gem "neovim" is out-of-date. Installed: '
+ .. current_gem
+ .. ', latest: '
+ .. latest_gem
+ health.warn(message, 'Run in shell: gem update neovim')
+ else
+ health.ok('Latest "neovim" gem is installed: ' .. current_gem)
+ end
+end
+
+return M