From 9dd112dd4821a325a6c1c8d952a537f42f9c728c Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 2 Apr 2024 12:36:13 +0200 Subject: refactor: remove fn_bool It's better to use vim.fn directly instead of creating minor abstractions like fn_bool. --- runtime/lua/provider/node/health.lua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'runtime/lua/provider/node') diff --git a/runtime/lua/provider/node/health.lua b/runtime/lua/provider/node/health.lua index a434f8a92b..b4dca2f482 100644 --- a/runtime/lua/provider/node/health.lua +++ b/runtime/lua/provider/node/health.lua @@ -1,5 +1,4 @@ local health = vim.health -local executable = health.executable local iswin = vim.loop.os_uname().sysname == 'Windows_NT' local M = {} @@ -12,8 +11,12 @@ function M.check() end if - not executable('node') - or (not executable('npm') and not executable('yarn') and not executable('pnpm')) + 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.', @@ -50,9 +53,9 @@ function M.check() health.info('Nvim node.js host: ' .. host) local manager = 'npm' - if executable('yarn') then + if vim.fn.executable('yarn') == 1 then manager = 'yarn' - elseif executable('pnpm') then + elseif vim.fn.executable('pnpm') == 1 then manager = 'pnpm' end -- cgit From 603f3b36a4d543bc539a5abad8ac93a2595e3995 Mon Sep 17 00:00:00 2001 From: Ivan Georgiev Date: Mon, 15 Apr 2024 19:23:22 +0300 Subject: fix(checkhealth): error in node.js check #28348 Problem: :checkhealth node.js check fails: ERROR Failed to run healthcheck for "provider.node" plugin ... node/health.lua:98: attempt to call local 'message' (a string value) `message` is called as a function, when it is actually a string. Solution: Pass `message` to `warn()` as an argument. Fix #28346 --- runtime/lua/provider/node/health.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'runtime/lua/provider/node') diff --git a/runtime/lua/provider/node/health.lua b/runtime/lua/provider/node/health.lua index b4dca2f482..471c625388 100644 --- a/runtime/lua/provider/node/health.lua +++ b/runtime/lua/provider/node/health.lua @@ -92,14 +92,15 @@ function M.check() 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 - .. ' latest: ' - .. latest_npm - health.warn(message({ + .. 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 -- cgit From 0f4f7d32ce5d6d3b751b0b01455770f3b72531b9 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 18 May 2024 18:35:26 +0200 Subject: 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.*`. --- runtime/lua/provider/node/health.lua | 109 ----------------------------------- 1 file changed, 109 deletions(-) delete mode 100644 runtime/lua/provider/node/health.lua (limited to 'runtime/lua/provider/node') diff --git a/runtime/lua/provider/node/health.lua b/runtime/lua/provider/node/health.lua deleted file mode 100644 index 471c625388..0000000000 --- a/runtime/lua/provider/node/health.lua +++ /dev/null @@ -1,109 +0,0 @@ -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 -- cgit