Use a more reliable method for getting an ID for a job

This commit is contained in:
w0rp 2017-02-17 10:19:44 +00:00
parent bdbf36991d
commit b21ca4ed4e
2 changed files with 12 additions and 13 deletions

View file

@ -9,25 +9,19 @@
" output: The array of lines for the output of the job.
let s:job_info_map = {}
function! ale#engine#ParseVim8ProcessID(job_string) abort
return matchstr(a:job_string, '\d\+') + 0
endfunction
function! s:GetJobID(job) abort
if has('nvim')
"In NeoVim, job values are just IDs.
return a:job
endif
" In Vim 8, the job is a special variable, and we open a channel for each
" job. We'll use the ID of the channel instead as the job ID.
try
let l:channel_info = ch_info(job_getchannel(a:job))
if !empty(l:channel_info)
return l:channel_info.id
endif
catch
endtry
" If we fail to get the channel ID for a job, just return a 0 ID.
return 0
" For Vim 8, the job is a different variable type, and we can parse the
" process ID from the string.
return ale#engine#ParseVim8ProcessID(string(a:job))
endfunction
function! ale#engine#InitBufferInfo(buffer) abort

View file

@ -0,0 +1,5 @@
Execute(Vim8 Process ID parsing should work):
AssertEqual 123, ale#engine#ParseVim8ProcessID('process 123 run')
AssertEqual 347, ale#engine#ParseVim8ProcessID('process 347 failed')
AssertEqual 789, ale#engine#ParseVim8ProcessID('process 789 dead')
AssertEqual 0, ale#engine#ParseVim8ProcessID('no process')