diff options
author | Marco Hinz <mh.codebro@gmail.com> | 2017-01-06 16:11:02 +0100 |
---|---|---|
committer | Marco Hinz <mh.codebro@gmail.com> | 2017-01-07 16:56:38 +0100 |
commit | 40c76741c187f5bf35101e65252226030d5b72e5 (patch) | |
tree | efe3aecaa646ce416f3001c35bf3e3584f540caa | |
parent | b4c0c61f5caa22962ba94981dece4be8bf8a2c26 (diff) | |
download | rneovim-40c76741c187f5bf35101e65252226030d5b72e5.tar.gz rneovim-40c76741c187f5bf35101e65252226030d5b72e5.tar.bz2 rneovim-40c76741c187f5bf35101e65252226030d5b72e5.zip |
health: refactor s:check_ruby()
I gone through every single line, renamed the variables to be more consistent
and reordered many lines. Information is now printed as soon as it's available
and errors lead to early returns.
I altered the suggestions for each condition to be more precise and checked that
they fail properly.
This also prevents invalid arguments getting passed to s:version_cmp().
-rw-r--r-- | runtime/autoload/health/provider.vim | 69 |
1 files changed, 40 insertions, 29 deletions
diff --git a/runtime/autoload/health/provider.vim b/runtime/autoload/health/provider.vim index 9cf540ba09..2f98dd076e 100644 --- a/runtime/autoload/health/provider.vim +++ b/runtime/autoload/health/provider.vim @@ -405,38 +405,49 @@ endfunction function! s:check_ruby() abort call health#report_start('Ruby provider') - let ruby_version = 'not found' - if executable('ruby') - let ruby_version = s:systemlist('ruby -v')[0] + + if !executable('ruby') || !executable('gem') + call health#report_warn( + \ "Both `ruby` and `gem` have to be in $PATH. Ruby code won't work.", + \ ["Install Ruby and make sure that `ruby` and `gem` are in $PATH."]) + return endif - let ruby_prog = provider#ruby#Detect() - let suggestions = - \ ['Install or upgrade the neovim RubyGem using `gem install neovim`.'] - - if empty(ruby_prog) - let ruby_prog = 'not found' - let prog_vers = 'not found' - call health#report_error('Missing Neovim RubyGem', suggestions) - else - silent let latest_gem = get(split(s:system(['gem', 'list', '-ra', '^neovim$']), - \ ' (\|, \|)$' ), 1, 'not found') - let latest_desc = ' (latest: ' . latest_gem . ')' - - silent let prog_vers = s:systemlist(ruby_prog . ' --version')[0] - if s:shell_error - let prog_vers = 'not found' . latest_desc - call health#report_warn('Neovim RubyGem is not up-to-date.', suggestions) - elseif s:version_cmp(prog_vers, latest_gem) == -1 - let prog_vers .= latest_desc - call health#report_warn('Neovim RubyGem is not up-to-date.', suggestions) - else - call health#report_ok('Found up-to-date neovim RubyGem') - endif + call health#report_info('Ruby: '. s:system('ruby -v')) + + let host = provider#ruby#Detect() + if empty(host) + call health#report_warn("Missing \"neovim\" gem. Ruby code won't work.", + \ ['Run in shell: gem install neovim']) + return + endif + call health#report_info('Host: '. host) + + let latest_gem_cmd = 'gem list -rae 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, ' (\|, \|)$' ), 1, '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: '. current_gem_cmd, + \ ["Report this issue with the output of: ", current_gem_cmd]) + return endif - call health#report_info('Ruby Version: ' . ruby_version) - call health#report_info('Host Executable: ' . ruby_prog) - call health#report_info('Host Version: ' . prog_vers) + if s:version_cmp(current_gem, latest_gem) == -1 + 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('Gem "neovim" is up-to-date: '. current_gem) + endif endfunction function! health#provider#check() abort |