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
|
endif
|
||||||
call health#report_info('Ruby: '. s:system('ruby -v'))
|
call health#report_info('Ruby: '. s:system('ruby -v'))
|
||||||
|
|
||||||
let host = provider#ruby#Detect()
|
let [host, err] = provider#ruby#Detect()
|
||||||
if empty(host)
|
if empty(host)
|
||||||
call health#report_warn('`neovim-ruby-host` not found.',
|
call health#report_warn('`neovim-ruby-host` not found.',
|
||||||
\ ['Run `gem install neovim` to ensure the neovim RubyGem is installed.',
|
\ ['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.')
|
call health#report_warn('node.js on this system does not support --inspect-brk so $NVIM_NODE_HOST_DEBUG is ignored.')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let host = provider#node#Detect()
|
let [host, err] = provider#node#Detect()
|
||||||
if empty(host)
|
if empty(host)
|
||||||
call health#report_warn('Missing "neovim" npm (or yarn) package.',
|
call health#report_warn('Missing "neovim" npm (or yarn) package.',
|
||||||
\ ['Run in shell: npm install -g neovim',
|
\ ['Run in shell: npm install -g neovim',
|
||||||
|
@ -48,14 +48,15 @@ function! provider#node#can_inspect() abort
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! provider#node#Detect() abort
|
function! provider#node#Detect() abort
|
||||||
|
let minver = [6, 0]
|
||||||
if exists('g:node_host_prog')
|
if exists('g:node_host_prog')
|
||||||
return expand(g:node_host_prog)
|
return [expand(g:node_host_prog), '']
|
||||||
endif
|
endif
|
||||||
if !executable('node')
|
if !executable('node')
|
||||||
return ''
|
return ['', 'node not found (or not executable)']
|
||||||
endif
|
endif
|
||||||
if !s:is_minimum_version(v:null, 6, 0)
|
if !s:is_minimum_version(v:null, minver[0], minver[1])
|
||||||
return ''
|
return ['', printf('node version %s.%s not found', minver[0], minver[1])]
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let npm_opts = {}
|
let npm_opts = {}
|
||||||
@ -75,7 +76,7 @@ function! provider#node#Detect() abort
|
|||||||
if has('unix')
|
if has('unix')
|
||||||
let yarn_default_path = $HOME . '/.config/yarn/global/' . yarn_opts.entry_point
|
let yarn_default_path = $HOME . '/.config/yarn/global/' . yarn_opts.entry_point
|
||||||
if filereadable(yarn_default_path)
|
if filereadable(yarn_default_path)
|
||||||
return yarn_default_path
|
return [yarn_default_path, '']
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
let yarn_opts.job_id = jobstart('yarn global dir', yarn_opts)
|
let yarn_opts.job_id = jobstart('yarn global dir', yarn_opts)
|
||||||
@ -85,18 +86,18 @@ function! provider#node#Detect() abort
|
|||||||
if !empty(npm_opts)
|
if !empty(npm_opts)
|
||||||
let result = jobwait([npm_opts.job_id])
|
let result = jobwait([npm_opts.job_id])
|
||||||
if result[0] == 0 && npm_opts.result != ''
|
if result[0] == 0 && npm_opts.result != ''
|
||||||
return npm_opts.result
|
return [npm_opts.result, '']
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !empty(yarn_opts)
|
if !empty(yarn_opts)
|
||||||
let result = jobwait([yarn_opts.job_id])
|
let result = jobwait([yarn_opts.job_id])
|
||||||
if result[0] == 0 && yarn_opts.result != ''
|
if result[0] == 0 && yarn_opts.result != ''
|
||||||
return yarn_opts.result
|
return [yarn_opts.result, '']
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return ''
|
return ['', 'failed to detect node']
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! provider#node#Prog() abort
|
function! provider#node#Prog() abort
|
||||||
@ -142,7 +143,7 @@ endfunction
|
|||||||
|
|
||||||
|
|
||||||
let s:err = ''
|
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
|
let g:loaded_node_provider = empty(s:prog) ? 1 : 2
|
||||||
|
|
||||||
if g:loaded_node_provider != 2
|
if g:loaded_node_provider != 2
|
||||||
|
@ -5,7 +5,8 @@ endif
|
|||||||
let g:loaded_ruby_provider = 1
|
let g:loaded_ruby_provider = 1
|
||||||
|
|
||||||
function! provider#ruby#Detect() abort
|
function! provider#ruby#Detect() abort
|
||||||
return s:prog
|
let e = empty(s:prog) ? 'missing ruby or ruby-host' : ''
|
||||||
|
return [s:prog, e]
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! provider#ruby#Prog() abort
|
function! provider#ruby#Prog() abort
|
||||||
|
@ -768,18 +768,15 @@ function module.new_pipename()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function module.missing_provider(provider)
|
function module.missing_provider(provider)
|
||||||
if provider == 'ruby' or provider == 'node' then
|
if provider == 'ruby' or provider == 'node' or provider == 'perl' then
|
||||||
local prog = module.funcs['provider#' .. provider .. '#Detect']()
|
local e = module.funcs['provider#'..provider..'#Detect']()[2]
|
||||||
return prog == '' and (provider .. ' not detected') or false
|
return e ~= '' and e or false
|
||||||
elseif provider == 'perl' then
|
|
||||||
local errors = module.funcs['provider#'..provider..'#Detect']()[2]
|
|
||||||
return errors ~= '' and errors or false
|
|
||||||
elseif provider == 'python' or provider == 'python3' then
|
elseif provider == 'python' or provider == 'python3' then
|
||||||
local py_major_version = (provider == 'python3' and 3 or 2)
|
local py_major_version = (provider == 'python3' and 3 or 2)
|
||||||
local errors = module.funcs['provider#pythonx#Detect'](py_major_version)[2]
|
local e = module.funcs['provider#pythonx#Detect'](py_major_version)[2]
|
||||||
return errors ~= '' and errors or false
|
return e ~= '' and e or false
|
||||||
else
|
else
|
||||||
assert(false, 'Unknown provider: ' .. provider)
|
assert(false, 'Unknown provider: '..provider)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user