mirror of
https://github.com/neovim/neovim.git
synced 2025-12-16 11:25:33 +00:00
refactor: rewrite ruby healthcheck in lua
This is required to remove the vimscript checkhealth functions.
This commit is contained in:
@@ -1,10 +1,5 @@
|
|||||||
let s:shell_error = 0
|
let s:shell_error = 0
|
||||||
|
|
||||||
" Convert '\' to '/'. Collapse '//' and '/./'.
|
|
||||||
function! s:normalize_path(s) abort
|
|
||||||
return substitute(substitute(a:s, '\', '/', 'g'), '/\./\|/\+', '/', 'g')
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
" Handler for s:system() function.
|
" Handler for s:system() function.
|
||||||
function! s:system_handler(jobid, data, event) dict abort
|
function! s:system_handler(jobid, data, event) dict abort
|
||||||
if a:event ==# 'stderr'
|
if a:event ==# 'stderr'
|
||||||
@@ -90,61 +85,6 @@ function! s:disabled_via_loaded_var(provider) abort
|
|||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:check_ruby() abort
|
|
||||||
call health#report_start('Ruby provider (optional)')
|
|
||||||
|
|
||||||
if s:disabled_via_loaded_var('ruby')
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
if !executable('ruby') || !executable('gem')
|
|
||||||
call health#report_warn(
|
|
||||||
\ '`ruby` and `gem` must be in $PATH.',
|
|
||||||
\ ['Install Ruby and verify that `ruby` and `gem` commands work.'])
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
call health#report_info('Ruby: '. s:system(['ruby', '-v']))
|
|
||||||
|
|
||||||
let [host, err] = provider#ruby#Detect()
|
|
||||||
if empty(host)
|
|
||||||
call health#report_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
|
|
||||||
endif
|
|
||||||
call health#report_info('Host: '. host)
|
|
||||||
|
|
||||||
let latest_gem_cmd = has('win32') ? 'cmd /c gem list -ra "^^neovim$"' : 'gem list -ra ^neovim$'
|
|
||||||
let latest_gem = s:system(split(latest_gem_cmd))
|
|
||||||
if s:shell_error || empty(latest_gem)
|
|
||||||
call health#report_error('Failed to run: '. latest_gem_cmd,
|
|
||||||
\ ["Make sure you're connected to the internet.",
|
|
||||||
\ 'Are you behind a firewall or proxy?'])
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
let latest_gem = get(split(latest_gem, 'neovim (\|, \|)$' ), 0, 'not found')
|
|
||||||
|
|
||||||
let current_gem_cmd = [host, '--version']
|
|
||||||
let current_gem = s:system(current_gem_cmd)
|
|
||||||
if s:shell_error
|
|
||||||
call health#report_error('Failed to run: '. join(current_gem_cmd),
|
|
||||||
\ ['Report this issue with the output of: ', join(current_gem_cmd)])
|
|
||||||
return
|
|
||||||
endif
|
|
||||||
|
|
||||||
if v:lua.vim.version.lt(current_gem, latest_gem)
|
|
||||||
call health#report_warn(
|
|
||||||
\ printf('Gem "neovim" is out-of-date. Installed: %s, latest: %s',
|
|
||||||
\ current_gem, latest_gem),
|
|
||||||
\ ['Run in shell: gem update neovim'])
|
|
||||||
else
|
|
||||||
call health#report_ok('Latest "neovim" gem is installed: '. current_gem)
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:check_node() abort
|
function! s:check_node() abort
|
||||||
call health#report_start('Node.js provider (optional)')
|
call health#report_start('Node.js provider (optional)')
|
||||||
|
|
||||||
@@ -299,7 +239,6 @@ function! s:check_perl() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! health#provider2#check() abort
|
function! health#provider2#check() abort
|
||||||
call s:check_ruby()
|
|
||||||
call s:check_node()
|
call s:check_node()
|
||||||
call s:check_perl()
|
call s:check_perl()
|
||||||
endfunction
|
endfunction
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ local function system(cmd, ...)
|
|||||||
|
|
||||||
-- return opts.output
|
-- return opts.output
|
||||||
local _ = ...
|
local _ = ...
|
||||||
return vim.fn.system(cmd)
|
return vim.trim(vim.fn.system(cmd))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function clipboard()
|
local function clipboard()
|
||||||
@@ -657,10 +657,74 @@ local function virtualenv()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function ruby()
|
||||||
|
start('Ruby provider (optional)')
|
||||||
|
|
||||||
|
if disabled_via_loaded_var('ruby') then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if not executable('ruby') or not executable('gem') then
|
||||||
|
warn(
|
||||||
|
'`ruby` and `gem` must be in $PATH.',
|
||||||
|
'Install Ruby and verify that `ruby` and `gem` commands work.'
|
||||||
|
)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
info('Ruby: ' .. system({ 'ruby', '-v' }))
|
||||||
|
|
||||||
|
local ruby_detect_table = vim.fn['provider#ruby#Detect']()
|
||||||
|
local host = ruby_detect_table[1]
|
||||||
|
if is_blank(host) then
|
||||||
|
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
|
||||||
|
info('Host: ' .. host)
|
||||||
|
|
||||||
|
local latest_gem_cmd = (iswin and 'cmd /c gem list -ra "^^neovim$"' or 'gem list -ra ^neovim$')
|
||||||
|
local latest_gem = system(vim.fn.split(latest_gem_cmd))
|
||||||
|
if shell_error() or is_blank(latest_gem) then
|
||||||
|
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 = system(current_gem_cmd)
|
||||||
|
if shell_error() then
|
||||||
|
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
|
||||||
|
warn(message, 'Run in shell: gem update neovim')
|
||||||
|
else
|
||||||
|
ok('Latest "neovim" gem is installed: ' .. current_gem)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function M.check()
|
function M.check()
|
||||||
clipboard()
|
clipboard()
|
||||||
python()
|
python()
|
||||||
virtualenv()
|
virtualenv()
|
||||||
|
ruby()
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user