provider/nodejs: check version in Detect()

This commit is contained in:
Justin M. Keyes 2017-12-17 15:53:11 +01:00
parent e0054fef7d
commit 103ff26c0a
6 changed files with 42 additions and 28 deletions

View File

@ -5,24 +5,35 @@ let g:loaded_node_provider = 1
let s:job_opts = {'rpc': v:true, 'on_stderr': function('provider#stderr_collector')}
function! s:is_minimum_version(version, min_major, min_minor) abort
let nodejs_version = a:version
if !a:version
let nodejs_version = get(split(system(['node', '-v']), "\n"), 0, '')
if v:shell_error || nodejs_version[0] !=# 'v'
return 0
endif
endif
" [major, minor, patch]
let v_list = !!a:version ? a:version : split(nodejs_version[1:], '\.')
return len(v_list) == 3
\ && ((str2nr(v_list[0]) > str2nr(a:min_major))
\ || (str2nr(v_list[0]) == str2nr(a:min_major)
\ && str2nr(v_list[1]) >= str2nr(a:min_minor)))
endfunction
" Support for --inspect-brk requires node 6.12+ or 7.6+ or 8+
" Return 1 if it is supported
" Return 0 otherwise
function! provider#node#can_inspect()
function! provider#node#can_inspect() abort
if !executable('node')
return 0
endif
let node_v = get(split(system(['node', '-v']), "\n"), 0, '')
if v:shell_error || node_v[0] !=# 'v'
let ver = get(split(system(['node', '-v']), "\n"), 0, '')
if v:shell_error || ver[0] !=# 'v'
return 0
endif
" [major, minor, patch]
let node_v = split(node_v[1:], '\.')
return len(node_v) == 3 && (
\ (node_v[0] > 7) ||
\ (node_v[0] == 7 && node_v[1] >= 6) ||
\ (node_v[0] == 6 && node_v[1] >= 12)
\ )
return (ver[1] ==# '6' && s:is_minimum_version(ver, 6, 12))
\ || s:is_minimum_version(ver, 7, 6)
endfunction
function! provider#node#Detect() abort
@ -30,10 +41,17 @@ function! provider#node#Detect() abort
if v:shell_error || !isdirectory(global_modules)
return ''
endif
return glob(global_modules . '/neovim/bin/cli.js')
if !s:is_minimum_version(v:null, 6, 0)
return ''
endif
let entry_point = glob(global_modules . '/neovim/bin/cli.js')
if !filereadable(entry_point)
return ''
endif
return entry_point
endfunction
function! provider#node#Prog()
function! provider#node#Prog() abort
return s:prog
endfunction
@ -69,7 +87,7 @@ function! provider#node#Require(host) abort
throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_NODE_LOG_FILE')
endfunction
function! provider#node#Call(method, args)
function! provider#node#Call(method, args) abort
if s:err != ''
echoerr s:err
return

View File

@ -11,11 +11,11 @@ let g:loaded_python_provider = 1
let [s:prog, s:err] = provider#pythonx#Detect(2)
function! provider#python#Prog()
function! provider#python#Prog() abort
return s:prog
endfunction
function! provider#python#Error()
function! provider#python#Error() abort
return s:err
endfunction
@ -29,7 +29,7 @@ endif
call remote#host#RegisterClone('legacy-python-provider', 'python')
call remote#host#RegisterPlugin('legacy-python-provider', 'script_host.py', [])
function! provider#python#Call(method, args)
function! provider#python#Call(method, args) abort
if s:err != ''
return
endif

View File

@ -11,11 +11,11 @@ let g:loaded_python3_provider = 1
let [s:prog, s:err] = provider#pythonx#Detect(3)
function! provider#python3#Prog()
function! provider#python3#Prog() abort
return s:prog
endfunction
function! provider#python3#Error()
function! provider#python3#Error() abort
return s:err
endfunction
@ -29,7 +29,7 @@ endif
call remote#host#RegisterClone('legacy-python3-provider', 'python3')
call remote#host#RegisterPlugin('legacy-python3-provider', 'script_host.py', [])
function! provider#python3#Call(method, args)
function! provider#python3#Call(method, args) abort
if s:err != ''
return
endif

View File

@ -7,7 +7,7 @@ let g:loaded_ruby_provider = 1
let s:stderr = {}
let s:job_opts = {'rpc': v:true}
function! s:job_opts.on_stderr(chan_id, data, event)
function! s:job_opts.on_stderr(chan_id, data, event) abort
let stderr = get(s:stderr, a:chan_id, [''])
let last = remove(stderr, -1)
let a:data[0] = last.a:data[0]
@ -23,7 +23,7 @@ function! provider#ruby#Detect() abort
end
endfunction
function! provider#ruby#Prog()
function! provider#ruby#Prog() abort
return s:prog
endfunction
@ -50,7 +50,7 @@ function! provider#ruby#Require(host) abort
throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_RUBY_LOG_FILE')
endfunction
function! provider#ruby#Call(method, args)
function! provider#ruby#Call(method, args) abort
if s:err != ''
echoerr s:err
return

View File

@ -9,9 +9,7 @@ local retry = helpers.retry
do
clear()
if missing_provider('node') then
pending(
"Cannot find the neovim nodejs host. Try :checkhealth",
function() end)
pending("Missing nodejs host, or nodejs version is too old.", function()end)
return
end
end

View File

@ -15,9 +15,7 @@ local missing_provider = helpers.missing_provider
do
clear()
if missing_provider('ruby') then
pending(
"Cannot find the neovim RubyGem. Try :checkhealth",
function() end)
pending("Missing neovim RubyGem.", function() end)
return
end
end