mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
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.
This commit is contained in:
parent
fb55cb2d91
commit
bedab7e87b
@ -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',
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user