aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2022-10-30 06:41:28 +0100
committerJustin M. Keyes <justinkz@gmail.com>2022-10-30 16:23:58 +0100
commitcc7c378bf319d62491ca121ab598397428e4ced4 (patch)
treed42b3cc266d34ff80736060dd52ad3a30a1a8ccd
parent3213bc36c5d0cddf8f81498a1ac590bc6d81d743 (diff)
downloadrneovim-cc7c378bf319d62491ca121ab598397428e4ced4.tar.gz
rneovim-cc7c378bf319d62491ca121ab598397428e4ced4.tar.bz2
rneovim-cc7c378bf319d62491ca121ab598397428e4ced4.zip
feat(checkhealth): check runtime ($VIMRUNTIME)
Move man/health.lua into the "runtime" check. fix #20696
-rw-r--r--runtime/lua/man/health.lua20
-rw-r--r--runtime/lua/nvim/health.lua148
-rw-r--r--runtime/lua/vim/treesitter/health.lua4
-rw-r--r--test/functional/plugin/health_spec.lua5
4 files changed, 113 insertions, 64 deletions
diff --git a/runtime/lua/man/health.lua b/runtime/lua/man/health.lua
deleted file mode 100644
index 11d7148216..0000000000
--- a/runtime/lua/man/health.lua
+++ /dev/null
@@ -1,20 +0,0 @@
-local M = {}
-
-local report_ok = vim.fn['health#report_ok']
-local report_error = vim.fn['health#report_error']
-
-local function check_runtime_file(name)
- local path = vim.env.VIMRUNTIME .. '/' .. name
- if vim.loop.fs_stat(path) then
- report_error(string.format('%s detected. Please delete %s', name, path))
- else
- report_ok(string.format('%s not in $VIMRUNTIME', name))
- end
-end
-
-function M.check()
- check_runtime_file('plugin/man.vim')
- check_runtime_file('autoload/man.vim')
-end
-
-return M
diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua
index a8464b491a..413eae0bf9 100644
--- a/runtime/lua/nvim/health.lua
+++ b/runtime/lua/nvim/health.lua
@@ -3,68 +3,134 @@ local health = require('vim.health')
local suggest_faq = 'https://github.com/neovim/neovim/wiki/FAQ'
+local function check_runtime()
+ health.report_start('Runtime')
+ -- Files from an old installation.
+ local bad_files = {
+ ['plugin/man.vim'] = false,
+ ['scripts.vim'] = false,
+ ['autoload/man.vim'] = false,
+ }
+ local bad_files_msg = ''
+ for k, _ in pairs(bad_files) do
+ local path = ('%s/%s'):format(vim.env.VIMRUNTIME, k)
+ if vim.loop.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.report_ok or health.report_info
+ info(string.format('$VIMRUNTIME: %s', vim.env.VIMRUNTIME))
+ if not ok then
+ health.report_error(
+ string.format(
+ '$VIMRUNTIME has files from an old installation (this can cause weird behavior):\n%s',
+ bad_files_msg
+ ),
+ { 'Delete $VIMRUNTIME (or uninstall Nvim), then reinstall Nvim.' }
+ )
+ end
+end
+
local function check_config()
health.report_start('Configuration')
local ok = true
- local empty = function(o) return 0 ~= vim.fn.empty(o) end
- local filereadable = function(o) return 0 ~= vim.fn.filereadable(o) end
- local filewritable = function(o) return 0 ~= vim.fn.filewritable(o) end
+ local empty = function(o)
+ return 0 ~= vim.fn.empty(o)
+ end
+ local filereadable = function(o)
+ return 0 ~= vim.fn.filereadable(o)
+ end
+ local filewritable = function(o)
+ return 0 ~= vim.fn.filewritable(o)
+ end
- local vimrc = empty(vim.env.MYVIMRC) and vim.fn.stdpath('config')..'/init.vim' or vim.env.MYVIMRC
+ local vimrc = (
+ empty(vim.env.MYVIMRC) and vim.fn.stdpath('config') .. '/init.vim' or vim.env.MYVIMRC
+ )
if not filereadable(vimrc) then
ok = false
local has_vim = filereadable(vim.fn.expand('~/.vimrc'))
- health.report_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' })
+ health.report_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' }
+ )
end
-- 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
+ 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.report_error('$VIM is invalid: ' .. vim.env.VIM)
end
if 1 == vim.fn.exists('$NVIM_TUI_ENABLE_CURSOR_SHAPE') then
ok = false
- health.report_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' })
+ health.report_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.report_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.' })
+ health.report_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.report_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.', })
+ health.report_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 = (empty(vim.o.shada)
- and vim.o.shada
- or vim.fn.substitute(vim.fn.matchstr(shadaopt[#shadaopt], '^n.\\+'), '^n', '', ''))
- shadafile = (empty(vim.o.shadafile)
- and (empty(shadafile) and vim.fn.stdpath('state')..'/shada/main.shada' or vim.fn.expand(shadafile))
- or (vim.o.shadafile == 'NONE' and '' or vim.o.shadafile))
+ local shadafile = (
+ empty(vim.o.shada) and vim.o.shada
+ or vim.fn.substitute(vim.fn.matchstr(shadaopt[#shadaopt], '^n.\\+'), '^n', '', '')
+ )
+ shadafile = (
+ empty(vim.o.shadafile)
+ and (empty(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 not empty(shadafile) and empty(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 (not empty(shadafile) and (not filereadable(shadafile) or not filewritable(shadafile))) then
+ if
+ not writeable
+ or (not empty(shadafile) and (not filereadable(shadafile) or not filewritable(shadafile)))
+ then
ok = false
- health.report_error('shada file is not '
- ..((not writeable or filereadable(shadafile)) and 'writeable' or 'readable')..':\n'..shadafile)
+ health.report_error(
+ 'shada file is not '
+ .. ((not writeable or filereadable(shadafile)) and 'writeable' or 'readable')
+ .. ':\n'
+ .. shadafile
+ )
end
if ok then
@@ -75,7 +141,7 @@ end
local function check_performance()
vim.api.nvim_exec([=[
func! s:check_performance() abort
- let s:suggest_faq = ']=]..suggest_faq..[=['
+ let s:suggest_faq = ']=] .. suggest_faq .. [=['
call health#report_start('Performance')
@@ -105,13 +171,13 @@ local function check_performance()
endf
call s:check_performance()
- ]=],
- false)
+ ]=], false)
end
-- Load the remote plugin manifest file and check for unregistered plugins
local function check_rplugin_manifest()
- vim.api.nvim_exec([=[
+ vim.api.nvim_exec(
+ [=[
func! s:check_rplugin_manifest() abort
call health#report_start('Remote Plugins')
let existing_rplugins = {}
@@ -172,13 +238,13 @@ local function check_rplugin_manifest()
call s:check_rplugin_manifest()
]=],
- false)
+ false
+ )
end
-
local function check_tmux()
vim.api.nvim_exec([=[
- let s:suggest_faq = ']=]..suggest_faq..[=['
+ let s:suggest_faq = ']=] .. suggest_faq .. [=['
func! s:get_tmux_option(option) abort
let cmd = 'tmux show-option -qvg '.a:option " try global scope
@@ -258,7 +324,7 @@ local function check_tmux()
endif
" check for RGB capabilities
- let info = system(['tmux', 'server-info'])
+ let info = system(['tmux', 'show-messages', '-JT'])
let has_tc = stridx(info, " Tc: (flag) true") != -1
let has_rgb = stridx(info, " RGB: (flag) true") != -1
if !has_tc && !has_rgb
@@ -270,12 +336,12 @@ local function check_tmux()
endf
call s:check_tmux()
- ]=],
- false)
+ ]=], false)
end
local function check_terminal()
- vim.api.nvim_exec([=[
+ vim.api.nvim_exec(
+ [=[
func! s:check_terminal() abort
if !executable('infocmp')
return
@@ -307,11 +373,13 @@ local function check_terminal()
call s:check_terminal()
]=],
- false)
+ false
+ )
end
function M.check()
check_config()
+ check_runtime()
check_performance()
check_rplugin_manifest()
check_terminal()
diff --git a/runtime/lua/vim/treesitter/health.lua b/runtime/lua/vim/treesitter/health.lua
index 1c9b58c1a8..c0a1eca0ce 100644
--- a/runtime/lua/vim/treesitter/health.lua
+++ b/runtime/lua/vim/treesitter/health.lua
@@ -20,7 +20,9 @@ function M.check()
local is_loadable, ret = pcall(ts.language.require_language, parsername)
if not is_loadable or not ret then
- health.report_error(string.format('Parser "%s" failed to load (path: %s): %s', parsername, parser, ret or '?'))
+ health.report_error(
+ string.format('Parser "%s" failed to load (path: %s): %s', parsername, parser, ret or '?')
+ )
elseif ret then
local lang = ts.language.inspect_language(parsername)
health.report_ok(
diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua
index e5a60f5cb1..c970a03fcf 100644
--- a/test/functional/plugin/health_spec.lua
+++ b/test/functional/plugin/health_spec.lua
@@ -5,7 +5,7 @@ local Screen = require('test.functional.ui.screen')
local clear = helpers.clear
local curbuf_contents = helpers.curbuf_contents
local command = helpers.command
-local eq, neq = helpers.eq, helpers.neq
+local eq, neq, matches = helpers.eq, helpers.neq, helpers.matches
local getcompletion = helpers.funcs.getcompletion
describe(':checkhealth', function()
@@ -29,8 +29,7 @@ describe(':checkhealth', function()
-- Do this after startup, otherwise it just breaks $VIMRUNTIME.
command("let $VIM='zub'")
command("checkhealth nvim")
- eq("ERROR: $VIM is invalid: zub",
- string.match(curbuf_contents(), "ERROR: $VIM .* zub"))
+ matches('ERROR: $VIM .* zub', curbuf_contents())
end)
it('completions can be listed via getcompletion()', function()
clear()