From b21ca4ed4e09bd519ba2943aed17cff909dd71e2 Mon Sep 17 00:00:00 2001 From: w0rp Date: Fri, 17 Feb 2017 10:19:44 +0000 Subject: [PATCH] Use a more reliable method for getting an ID for a job --- autoload/ale/engine.vim | 20 +++++++------------- test/test_vim8_processid_parsing.vader | 5 +++++ 2 files changed, 12 insertions(+), 13 deletions(-) create mode 100644 test/test_vim8_processid_parsing.vader diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 593876f..61db4a1 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -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 diff --git a/test/test_vim8_processid_parsing.vader b/test/test_vim8_processid_parsing.vader new file mode 100644 index 0000000..5ec564e --- /dev/null +++ b/test/test_vim8_processid_parsing.vader @@ -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')