From 27b81af19c498892f4b0444ad29b7be842f8e7b8 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 30 Jan 2023 19:06:32 +0100 Subject: refactor!: remove has("debug") (#22060) This value can not be relied on as it doesn't work for multi-configuration generators. I don't think this undocumented option is used much, if at all, so I think we should remove it. --- runtime/lua/nvim/health.lua | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'runtime/lua/nvim') diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua index b76106f241..f11899434e 100644 --- a/runtime/lua/nvim/health.lua +++ b/runtime/lua/nvim/health.lua @@ -156,13 +156,10 @@ local function check_performance() health.report_ok(buildtype) else health.report_info(buildtype) - health.report_warn( - 'Non-optimized ' .. (has('debug') and '(DEBUG) ' or '') .. 'build. Nvim will be slower.', - { - 'Install a different Nvim package, or rebuild with `CMAKE_BUILD_TYPE=RelWithDebInfo`.', - suggest_faq, - } - ) + health.report_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 -- cgit From 6c39edaa7e5060cedfbbf61e88f4aad20fdff73d Mon Sep 17 00:00:00 2001 From: Mateusz Majewski Date: Mon, 6 Feb 2023 05:24:00 +0100 Subject: fix(health): iterate using ipairs correctly (#22119) In a few places ipairs was used to iterate over elements of the array. However, the first return value of ipairs was erronously used, which is not the value, but rather the index. This would result in errors, for instance when trying to retrieve a field from the value. --- runtime/lua/nvim/health.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'runtime/lua/nvim') diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua index f11899434e..b6d84404ec 100644 --- a/runtime/lua/nvim/health.lua +++ b/runtime/lua/nvim/health.lua @@ -183,7 +183,7 @@ local function check_rplugin_manifest() existing_rplugins[item.path] = 'python' end - for item in ipairs(vim.fn['remote#host#PluginsForHost']('python3')) do + for _, item in ipairs(vim.fn['remote#host#PluginsForHost']('python3')) do existing_rplugins[item.path] = 'python3' end @@ -200,7 +200,7 @@ local function check_rplugin_manifest() 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 + 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 @@ -384,7 +384,13 @@ local function check_terminal() ) end - for env_var in ipairs({ 'XTERM_VERSION', 'VTE_VERSION', 'TERM_PROGRAM', 'COLORTERM', 'SSH_TTY' }) do + for _, env_var in ipairs({ + 'XTERM_VERSION', + 'VTE_VERSION', + 'TERM_PROGRAM', + 'COLORTERM', + 'SSH_TTY', + }) do if vim.env[env_var] then health.report_info(vim.fn.printf('$%s="%s"', env_var, vim.env[env_var])) end -- cgit From 4d04feb6629cb049cb2a13ba35f0c8d3c6b67ff4 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Fri, 14 Apr 2023 10:39:57 +0200 Subject: feat(lua): vim.tbl_contains supports general tables and predicates (#23040) * feat(lua): vim.tbl_contains supports general tables and predicates Problem: `vim.tbl_contains` only works for list-like tables (integer keys without gaps) and primitive values (in particular, not for nested tables). Solution: Rename `vim.tbl_contains` to `vim.list_contains` and add new `vim.tbl_contains` that works for general tables and optionally allows `value` to be a predicate function that is checked for every key. --- runtime/lua/nvim/health.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/nvim') diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua index b6d84404ec..6f544e9407 100644 --- a/runtime/lua/nvim/health.lua +++ b/runtime/lua/nvim/health.lua @@ -325,7 +325,7 @@ local function check_tmux() -- check for RGB capabilities local info = vim.fn.system({ 'tmux', 'display-message', '-p', '#{client_termfeatures}' }) info = vim.split(vim.trim(info), ',', { trimempty = true }) - if not vim.tbl_contains(info, 'RGB') then + if not vim.list_contains(info, 'RGB') then local has_rgb = false if #info == 0 then -- client_termfeatures may not be supported; fallback to checking show-messages -- cgit From c08b03076167837cff9eb66c19440d727e6dad31 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sat, 15 Apr 2023 23:40:48 +0200 Subject: refactor: deprecate checkhealth functions The following functions are deprecated and will be removed in Nvim v0.11: - health#report_start() - health#report_info() - health#report_ok() - health#report_warn() - health#report_error() - vim.health.report_start() - vim.health.report_info() - vim.health.report_ok() - vim.health.report_warn() - vim.health.report_error() Users should instead use these: - vim.health.start() - vim.health.info() - vim.health.ok() - vim.health.warn() - vim.health.error() --- runtime/lua/nvim/health.lua | 83 ++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 43 deletions(-) (limited to 'runtime/lua/nvim') 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 -- cgit From 2db719f6c2b677fcbc197b02fe52764a851523b2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Sat, 3 Jun 2023 11:06:00 +0100 Subject: feat(lua): rename vim.loop -> vim.uv (#22846) --- runtime/lua/nvim/health.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'runtime/lua/nvim') diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua index 19303d34f9..7ccb082a40 100644 --- a/runtime/lua/nvim/health.lua +++ b/runtime/lua/nvim/health.lua @@ -30,7 +30,7 @@ local function check_runtime() 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 + if vim.uv.fs_stat(path) then bad_files[k] = true bad_files_msg = ('%s%s\n'):format(bad_files_msg, path) end -- cgit From 3bbb0aa3993fb8760fa693aae2133186cb61db77 Mon Sep 17 00:00:00 2001 From: Tom Blake Date: Sun, 24 Sep 2023 18:43:55 +0100 Subject: fix: checkhealth warning even if init.lua exists #25306 Problem: `:checkhealth nvim` warns about missing vimrc if `init.lua` exists but `init.vim` does not. Solution: Check for any of: init.vim, init.lua, $MYVIMRC. Fix #25291 --- runtime/lua/nvim/health.lua | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'runtime/lua/nvim') diff --git a/runtime/lua/nvim/health.lua b/runtime/lua/nvim/health.lua index 7ccb082a40..6b6370fa19 100644 --- a/runtime/lua/nvim/health.lua +++ b/runtime/lua/nvim/health.lua @@ -54,15 +54,19 @@ local function check_config() health.start('Configuration') local ok = true - local vimrc = ( - empty(vim.env.MYVIMRC) and vim.fn.stdpath('config') .. '/init.vim' or vim.env.MYVIMRC - ) - if not filereadable(vimrc) then + local init_lua = vim.fn.stdpath('config') .. '/init.lua' + local init_vim = vim.fn.stdpath('config') .. '/init.vim' + local vimrc = empty(vim.env.MYVIMRC) and init_lua or vim.env.MYVIMRC + + if not filereadable(vimrc) and not filereadable(init_vim) then ok = false local has_vim = filereadable(vim.fn.expand('~/.vimrc')) 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' } + ('%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 -- cgit