mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 20:20:05 +08:00
Add sync support
This commit is contained in:
parent
607882765f
commit
3e8a2dddc1
@ -5,11 +5,10 @@ endfunction
|
||||
" make vim and neovim use same job func.
|
||||
let s:self = {}
|
||||
let s:self.jobs = {}
|
||||
let s:self.nvim_job = has('nvim')
|
||||
let s:self.vim_job = !has('nvim') && has('job') && has('patch-8.0.0027')
|
||||
if !s:self.nvim_job && !s:self.vim_job
|
||||
let s:self.vim_co = SpaceVim#api#import('vim#compatible')
|
||||
endif
|
||||
let s:self.nvim_job = has('nvim') && 0
|
||||
let s:self.vim_job = !has('nvim') && has('job') && has('patch-8.0.0027') && 0
|
||||
let s:self.vim_co = SpaceVim#api#import('vim#compatible')
|
||||
|
||||
function! s:self.warn(...) abort
|
||||
if len(a:000) == 0
|
||||
echohl WarningMsg | echom 'Current version do not support job feature, fallback to sync system()' | echohl None
|
||||
@ -98,16 +97,19 @@ function! s:self.start(argv, ...) abort
|
||||
let opts = {}
|
||||
endif
|
||||
let output = self.vim_co.systemlist(a:argv)
|
||||
let id = len(self.jobs) + 1
|
||||
let id = -1
|
||||
if v:shell_error
|
||||
if has_key(opts,'on_stderr')
|
||||
call call(opts.on_stderr, [id, output, 'on_stderr'])
|
||||
call call(opts.on_stderr, [id, output, 'stderr'])
|
||||
endif
|
||||
else
|
||||
if has_key(opts,'on_stdout')
|
||||
call call(opts.on_stderr, [id, output, 'on_stdout'])
|
||||
call call(opts.on_stdout, [id, output, 'stdout'])
|
||||
endif
|
||||
endif
|
||||
if has_key(opts,'on_exit')
|
||||
call call(opts.on_exit, [id, v:shell_error, 'exit'])
|
||||
endif
|
||||
return id
|
||||
endif
|
||||
endfunction
|
||||
|
@ -2,6 +2,7 @@ function! SpaceVim#api#vim#compatible#get() abort
|
||||
return map({
|
||||
\ 'execute' : '',
|
||||
\ 'system' : '',
|
||||
\ 'systemlist' : '',
|
||||
\ },
|
||||
\ "function('s:' . v:key)"
|
||||
\ )
|
||||
|
@ -3,7 +3,7 @@ Execute ( SpaceVim api: job ):
|
||||
let argv = ['cat']
|
||||
let g:stdout = ''
|
||||
let stderr = ''
|
||||
let exit = 1
|
||||
let exit_data = 1
|
||||
function! s:on_stdout(id, data, event) abort
|
||||
if a:event ==# 'stdout'
|
||||
for a in a:data
|
||||
@ -12,7 +12,7 @@ Execute ( SpaceVim api: job ):
|
||||
endif
|
||||
endfor
|
||||
elseif a:event ==# 'exit'
|
||||
let g:exit = a:data
|
||||
let g:exit_data = a:data
|
||||
else
|
||||
let g:stderr = a:data
|
||||
endif
|
||||
@ -23,11 +23,17 @@ Execute ( SpaceVim api: job ):
|
||||
\ 'on_exit' : function('s:on_stdout'),
|
||||
\ }
|
||||
let jobid = job.start(argv,opt)
|
||||
call job.send(jobid, 'foo')
|
||||
sleep 10m
|
||||
AssertEqual stdout, 'foo'
|
||||
AssertEqual job.status(jobid), 'run'
|
||||
call job.stop(jobid)
|
||||
AssertEqual exit, 1
|
||||
if jobid >= 0
|
||||
call job.send(jobid, 'foo')
|
||||
sleep 10m
|
||||
AssertEqual stdout, 'foo'
|
||||
AssertEqual job.status(jobid), 'run'
|
||||
call job.stop(jobid)
|
||||
AssertEqual exit_data, 1
|
||||
else
|
||||
let jobid = job.start(['echo', 'foo'],opt)
|
||||
AssertEqual stdout, 'foo'
|
||||
AssertEqual exit_data, 0
|
||||
endif
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user