Merge pull request #8019 from jamessan/invalid-provider-stderr

Improve error handling and reduce duplication of providers' #Require()
This commit is contained in:
James McCoy 2018-02-19 20:10:10 -05:00 committed by GitHub
commit 6bbec71fde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 58 deletions

View File

@ -0,0 +1,21 @@
" Common functions for providers
" Start the provider and perform a 'poll' request
"
" Returns a valid channel on success
function! provider#Poll(argv, orig_name, log_env) abort
let job = {'rpc': v:true, 'stderr_buffered': v:true}
try
let channel_id = jobstart(a:argv, job)
if channel_id > 0 && rpcrequest(channel_id, 'poll') ==# 'ok'
return channel_id
endif
catch
echomsg v:throwpoint
echomsg v:exception
for row in get(job, 'stderr', [])
echomsg row
endfor
endtry
throw remote#host#LoadErrorForHost(a:orig_name, a:log_env)
endfunction

View File

@ -3,8 +3,6 @@ if exists('g:loaded_node_provider')
endif
let g:loaded_node_provider = 1
let s:job_opts = {'rpc': v:true, 'stderr_buffered': v:true}
function! s:is_minimum_version(version, min_major, min_minor) abort
if empty(a:version)
let nodejs_version = get(split(system(['node', '-v']), "\n"), 0, '')
@ -72,21 +70,7 @@ function! provider#node#Require(host) abort
call add(args, provider#node#Prog())
try
let job = copy(s:job_opts)
let channel_id = jobstart(args, job)
if rpcrequest(channel_id, 'poll') ==# 'ok'
return channel_id
endif
catch
echomsg v:throwpoint
echomsg v:exception
for row in job.stderr
echomsg row
endfor
endtry
endtry
throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_NODE_LOG_FILE')
return provider#Poll(args, a:host.orig_name, '$NVIM_NODE_LOG_FILE')
endfunction
function! provider#node#Call(method, args) abort

View File

@ -5,8 +5,6 @@ endif
let s:loaded_pythonx_provider = 1
let s:job_opts = {'rpc': v:true, 'stderr_buffered': v:true}
function! provider#pythonx#Require(host) abort
let ver = (a:host.orig_name ==# 'python') ? 2 : 3
@ -20,21 +18,7 @@ function! provider#pythonx#Require(host) abort
call add(args, plugin.path)
endfor
try
let job = copy(s:job_opts)
let channel_id = jobstart(args, job)
if rpcrequest(channel_id, 'poll') ==# 'ok'
return channel_id
endif
catch
echomsg v:throwpoint
echomsg v:exception
for row in job.stderr
echomsg row
endfor
endtry
throw remote#host#LoadErrorForHost(a:host.orig_name,
\ '$NVIM_PYTHON_LOG_FILE')
return provider#Poll(args, a:host.orig_name, '$NVIM_PYTHON_LOG_FILE')
endfunction
function! provider#pythonx#Detect(major_ver) abort

View File

@ -4,17 +4,6 @@ if exists('g:loaded_ruby_provider')
endif
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) abort
let stderr = get(s:stderr, a:chan_id, [''])
let last = remove(stderr, -1)
let a:data[0] = last.a:data[0]
call extend(stderr, a:data)
let s:stderr[a:chan_id] = stderr
endfunction
function! provider#ruby#Detect() abort
if exists("g:ruby_host_prog")
return g:ruby_host_prog
@ -35,19 +24,7 @@ function! provider#ruby#Require(host) abort
let prog .= " " . shellescape(plugin.path)
endfor
try
let channel_id = jobstart(prog, s:job_opts)
if rpcrequest(channel_id, 'poll') ==# 'ok'
return channel_id
endif
catch
echomsg v:throwpoint
echomsg v:exception
for row in get(s:stderr, channel_id, [])
echomsg row
endfor
endtry
throw remote#host#LoadErrorForHost(a:host.orig_name, '$NVIM_RUBY_LOG_FILE')
return provider#Poll(prog, a:host.orig_name, '$NVIM_RUBY_LOG_FILE')
endfunction
function! provider#ruby#Call(method, args) abort