mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
refactor: rewrite node healthcheck in lua
This is required to remove the vimscript checkhealth functions.
This commit is contained in:
parent
436e0147f4
commit
b5c0e7137c
@ -85,85 +85,6 @@ function! s:disabled_via_loaded_var(provider) abort
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
function! s:check_node() abort
|
||||
call health#report_start('Node.js provider (optional)')
|
||||
|
||||
if s:disabled_via_loaded_var('node')
|
||||
return
|
||||
endif
|
||||
|
||||
if !executable('node') || (!executable('npm') && !executable('yarn') && !executable('pnpm'))
|
||||
call health#report_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
|
||||
endif
|
||||
let node_v = get(split(s:system(['node', '-v']), "\n"), 0, '')
|
||||
call health#report_info('Node.js: '. node_v)
|
||||
if s:shell_error || v:lua.vim.version.lt(node_v[1:], '6.0.0')
|
||||
call health#report_warn('Nvim node.js host does not support Node '.node_v)
|
||||
" Skip further checks, they are nonsense if nodejs is too old.
|
||||
return
|
||||
endif
|
||||
if !provider#node#can_inspect()
|
||||
call health#report_warn('node.js on this system does not support --inspect-brk so $NVIM_NODE_HOST_DEBUG is ignored.')
|
||||
endif
|
||||
|
||||
let [host, err] = provider#node#Detect()
|
||||
if empty(host)
|
||||
call health#report_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
|
||||
endif
|
||||
call health#report_info('Nvim node.js host: '. host)
|
||||
|
||||
let manager = 'npm'
|
||||
if executable('yarn')
|
||||
let manager = 'yarn'
|
||||
elseif executable('pnpm')
|
||||
let manager = 'pnpm'
|
||||
endif
|
||||
|
||||
let latest_npm_cmd = has('win32') ?
|
||||
\ 'cmd /c '. manager .' info neovim --json' :
|
||||
\ manager .' info neovim --json'
|
||||
let latest_npm = s:system(split(latest_npm_cmd))
|
||||
if s:shell_error || empty(latest_npm)
|
||||
call health#report_error('Failed to run: '. latest_npm_cmd,
|
||||
\ ["Make sure you're connected to the internet.",
|
||||
\ 'Are you behind a firewall or proxy?'])
|
||||
return
|
||||
endif
|
||||
try
|
||||
let pkg_data = json_decode(latest_npm)
|
||||
catch /E474/
|
||||
return 'error: '.latest_npm
|
||||
endtry
|
||||
let latest_npm = get(get(pkg_data, 'dist-tags', {}), 'latest', 'unable to parse')
|
||||
|
||||
let current_npm_cmd = ['node', host, '--version']
|
||||
let current_npm = s:system(current_npm_cmd)
|
||||
if s:shell_error
|
||||
call health#report_error('Failed to run: '. join(current_npm_cmd),
|
||||
\ ['Report this issue with the output of: ', join(current_npm_cmd)])
|
||||
return
|
||||
endif
|
||||
|
||||
if latest_npm !=# 'unable to parse' && v:lua.vim.version.lt(current_npm, latest_npm)
|
||||
call health#report_warn(
|
||||
\ printf('Package "neovim" is out-of-date. Installed: %s, latest: %s',
|
||||
\ current_npm, latest_npm),
|
||||
\ ['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
|
||||
call health#report_ok('Latest "neovim" npm/yarn/pnpm package is installed: '. current_npm)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:check_perl() abort
|
||||
call health#report_start('Perl provider (optional)')
|
||||
|
||||
@ -239,6 +160,5 @@ function! s:check_perl() abort
|
||||
endfunction
|
||||
|
||||
function! health#provider2#check() abort
|
||||
call s:check_node()
|
||||
call s:check_perl()
|
||||
endfunction
|
||||
|
@ -720,11 +720,111 @@ local function ruby()
|
||||
end
|
||||
end
|
||||
|
||||
local function node()
|
||||
start('Node.js provider (optional)')
|
||||
|
||||
if disabled_via_loaded_var('node') then
|
||||
return
|
||||
end
|
||||
|
||||
if
|
||||
not executable('node')
|
||||
or (not executable('npm') and not executable('yarn') and not executable('pnpm'))
|
||||
then
|
||||
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 node_v = system({ 'node', '-v' })
|
||||
info('Node.js: ' .. node_v)
|
||||
if shell_error() or vim.version.lt(node_v, '6.0.0') then
|
||||
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
|
||||
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 is_blank(host) then
|
||||
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
|
||||
info('Nvim node.js host: ' .. host)
|
||||
|
||||
local manager = 'npm'
|
||||
if executable('yarn') then
|
||||
manager = 'yarn'
|
||||
elseif executable('pnpm') then
|
||||
manager = 'pnpm'
|
||||
end
|
||||
|
||||
local latest_npm_cmd = (
|
||||
iswin and 'cmd /c ' .. manager .. ' info neovim --json' or manager .. ' info neovim --json'
|
||||
)
|
||||
local latest_npm = system(vim.fn.split(latest_npm_cmd))
|
||||
if shell_error() or is_blank(latest_npm) then
|
||||
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, output = pcall(vim.fn.json_decode, latest_npm)
|
||||
local pkg_data
|
||||
if pcall_ok then
|
||||
pkg_data = output
|
||||
else
|
||||
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 = system(current_npm_cmd)
|
||||
if shell_error() then
|
||||
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
|
||||
.. ' latest: '
|
||||
.. latest_npm
|
||||
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
|
||||
ok('Latest "neovim" npm/yarn/pnpm package is installed: ' .. current_npm)
|
||||
end
|
||||
end
|
||||
|
||||
function M.check()
|
||||
clipboard()
|
||||
python()
|
||||
virtualenv()
|
||||
ruby()
|
||||
node()
|
||||
end
|
||||
|
||||
return M
|
||||
|
Loading…
Reference in New Issue
Block a user