diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2020-09-05 15:02:46 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-05 15:02:46 -0700 |
commit | bedab7e87b038da11f93484c1bc1e036fea520b9 (patch) | |
tree | bec94773b8733b5e6a43ab449a632c62a7cccbab | |
parent | fb55cb2d91382d2646205c9a7709f9517eb7f153 (diff) | |
download | rneovim-bedab7e87b038da11f93484c1bc1e036fea520b9.tar.gz rneovim-bedab7e87b038da11f93484c1bc1e036fea520b9.tar.bz2 rneovim-bedab7e87b038da11f93484c1bc1e036fea520b9.zip |
provider: align all foo#Detect() functions #12839
Problem: ruby#Detect() and node#Detect() don't return a [prog, err] pair
which means callers must special-case them.
Solution: align their return signatures with the perl/pythonx providers.
-rw-r--r-- | runtime/autoload/health/provider.vim | 4 | ||||
-rw-r--r-- | runtime/autoload/provider/node.vim | 19 | ||||
-rw-r--r-- | runtime/autoload/provider/ruby.vim | 3 | ||||
-rw-r--r-- | test/functional/helpers.lua | 15 |
4 files changed, 20 insertions, 21 deletions
diff --git a/runtime/autoload/health/provider.vim b/runtime/autoload/health/provider.vim index 418d7f880a..e8e38f581f 100644 --- a/runtime/autoload/health/provider.vim +++ b/runtime/autoload/health/provider.vim @@ -573,7 +573,7 @@ function! s:check_ruby() abort endif call health#report_info('Ruby: '. s:system('ruby -v')) - let host = provider#ruby#Detect() + 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.', @@ -636,7 +636,7 @@ function! s:check_node() abort call health#report_warn('node.js on this system does not support --inspect-brk so $NVIM_NODE_HOST_DEBUG is ignored.') endif - let host = provider#node#Detect() + let [host, err] = provider#node#Detect() if empty(host) call health#report_warn('Missing "neovim" npm (or yarn) package.', \ ['Run in shell: npm install -g neovim', diff --git a/runtime/autoload/provider/node.vim b/runtime/autoload/provider/node.vim index c5d5e87729..17b6137816 100644 --- a/runtime/autoload/provider/node.vim +++ b/runtime/autoload/provider/node.vim @@ -48,14 +48,15 @@ function! provider#node#can_inspect() abort endfunction function! provider#node#Detect() abort + let minver = [6, 0] if exists('g:node_host_prog') - return expand(g:node_host_prog) + return [expand(g:node_host_prog), ''] endif if !executable('node') - return '' + return ['', 'node not found (or not executable)'] endif - if !s:is_minimum_version(v:null, 6, 0) - return '' + if !s:is_minimum_version(v:null, minver[0], minver[1]) + return ['', printf('node version %s.%s not found', minver[0], minver[1])] endif let npm_opts = {} @@ -75,7 +76,7 @@ function! provider#node#Detect() abort if has('unix') let yarn_default_path = $HOME . '/.config/yarn/global/' . yarn_opts.entry_point if filereadable(yarn_default_path) - return yarn_default_path + return [yarn_default_path, ''] endif endif let yarn_opts.job_id = jobstart('yarn global dir', yarn_opts) @@ -85,18 +86,18 @@ function! provider#node#Detect() abort if !empty(npm_opts) let result = jobwait([npm_opts.job_id]) if result[0] == 0 && npm_opts.result != '' - return npm_opts.result + return [npm_opts.result, ''] endif endif if !empty(yarn_opts) let result = jobwait([yarn_opts.job_id]) if result[0] == 0 && yarn_opts.result != '' - return yarn_opts.result + return [yarn_opts.result, ''] endif endif - return '' + return ['', 'failed to detect node'] endfunction function! provider#node#Prog() abort @@ -142,7 +143,7 @@ endfunction let s:err = '' -let s:prog = provider#node#Detect() +let [s:prog, s:_] = provider#node#Detect() let g:loaded_node_provider = empty(s:prog) ? 1 : 2 if g:loaded_node_provider != 2 diff --git a/runtime/autoload/provider/ruby.vim b/runtime/autoload/provider/ruby.vim index f843050df9..1f49c623ac 100644 --- a/runtime/autoload/provider/ruby.vim +++ b/runtime/autoload/provider/ruby.vim @@ -5,7 +5,8 @@ endif let g:loaded_ruby_provider = 1 function! provider#ruby#Detect() abort - return s:prog + let e = empty(s:prog) ? 'missing ruby or ruby-host' : '' + return [s:prog, e] endfunction function! provider#ruby#Prog() abort diff --git a/test/functional/helpers.lua b/test/functional/helpers.lua index 82b6fb42e8..e4fb95442c 100644 --- a/test/functional/helpers.lua +++ b/test/functional/helpers.lua @@ -768,18 +768,15 @@ function module.new_pipename() end function module.missing_provider(provider) - if provider == 'ruby' or provider == 'node' then - local prog = module.funcs['provider#' .. provider .. '#Detect']() - return prog == '' and (provider .. ' not detected') or false - elseif provider == 'perl' then - local errors = module.funcs['provider#'..provider..'#Detect']()[2] - return errors ~= '' and errors or false + if provider == 'ruby' or provider == 'node' or provider == 'perl' then + local e = module.funcs['provider#'..provider..'#Detect']()[2] + return e ~= '' and e or false elseif provider == 'python' or provider == 'python3' then local py_major_version = (provider == 'python3' and 3 or 2) - local errors = module.funcs['provider#pythonx#Detect'](py_major_version)[2] - return errors ~= '' and errors or false + local e = module.funcs['provider#pythonx#Detect'](py_major_version)[2] + return e ~= '' and e or false else - assert(false, 'Unknown provider: ' .. provider) + assert(false, 'Unknown provider: '..provider) end end |