Automatically remove jobs from the internal map after they are done
This commit is contained in:
parent
5a947933d7
commit
204e3ca36b
@ -396,17 +396,7 @@ function! s:RunJob(options) abort
|
|||||||
let l:read_buffer = 0
|
let l:read_buffer = 0
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" The command will be executed in a subshell. This fixes a number of
|
let l:command = ale#job#PrepareCommand(l:command)
|
||||||
" issues, including reading the PATH variables correctly, %PATHEXT%
|
|
||||||
" expansion on Windows, etc.
|
|
||||||
"
|
|
||||||
" NeoVim handles this issue automatically if the command is a String,
|
|
||||||
" but we'll do this explicitly, so we use thes same exact command for both
|
|
||||||
" versions.
|
|
||||||
let l:command = has('win32')
|
|
||||||
\ ? 'cmd /c ' . l:command
|
|
||||||
\ : split(&shell) + split(&shellcmdflag) + [l:command]
|
|
||||||
|
|
||||||
let l:job_options = {
|
let l:job_options = {
|
||||||
\ 'mode': 'nl',
|
\ 'mode': 'nl',
|
||||||
\ 'exit_cb': function('s:HandleExit'),
|
\ 'exit_cb': function('s:HandleExit'),
|
||||||
|
@ -57,31 +57,72 @@ function! s:NeoVimCallback(job, data, event) abort
|
|||||||
\ a:data,
|
\ a:data,
|
||||||
\)
|
\)
|
||||||
else
|
else
|
||||||
|
try
|
||||||
call ale#util#GetFunction(l:job_info.exit_cb)(a:job, a:data)
|
call ale#util#GetFunction(l:job_info.exit_cb)(a:job, a:data)
|
||||||
|
finally
|
||||||
|
" Automatically forget about the job after it's done.
|
||||||
|
if has_key(s:job_map, a:job)
|
||||||
|
call remove(s:job_map, a:job)
|
||||||
|
endif
|
||||||
|
endtry
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:VimOutputCallback(channel, data) abort
|
function! s:VimOutputCallback(channel, data) abort
|
||||||
let l:job = ch_getjob(a:channel)
|
let l:job = ch_getjob(a:channel)
|
||||||
let l:job_id = ale#job#ParseVim8ProcessID(string(l:job))
|
let l:job_id = ale#job#ParseVim8ProcessID(string(l:job))
|
||||||
|
|
||||||
|
" Only call the callbacks for jobs which are valid.
|
||||||
|
if l:job_id > 0
|
||||||
call ale#util#GetFunction(s:job_map[l:job_id].out_cb)(l:job_id, a:data)
|
call ale#util#GetFunction(s:job_map[l:job_id].out_cb)(l:job_id, a:data)
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:VimErrorCallback(channel, data) abort
|
function! s:VimErrorCallback(channel, data) abort
|
||||||
let l:job = ch_getjob(a:channel)
|
let l:job = ch_getjob(a:channel)
|
||||||
let l:job_id = ale#job#ParseVim8ProcessID(string(l:job))
|
let l:job_id = ale#job#ParseVim8ProcessID(string(l:job))
|
||||||
|
|
||||||
|
" Only call the callbacks for jobs which are valid.
|
||||||
|
if l:job_id > 0
|
||||||
call ale#util#GetFunction(s:job_map[l:job_id].err_cb)(l:job_id, a:data)
|
call ale#util#GetFunction(s:job_map[l:job_id].err_cb)(l:job_id, a:data)
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:VimCloseCallback(channel) abort
|
function! s:VimCloseCallback(channel) abort
|
||||||
" Call job_status, which will trigger the exit callback below.
|
let l:job = ch_getjob(a:channel)
|
||||||
" This behaviour is described in :help job-status
|
let l:job_id = ale#job#ParseVim8ProcessID(string(l:job))
|
||||||
call job_status(ch_getjob(a:channel))
|
let l:info = s:job_map[l:job_id]
|
||||||
|
|
||||||
|
" job_status() can trigger the exit handler.
|
||||||
|
" The channel can close before the job has exited.
|
||||||
|
if job_status(l:job) ==# 'dead'
|
||||||
|
try
|
||||||
|
call ale#util#GetFunction(l:info.exit_cb)(l:job_id, l:info.exit_code)
|
||||||
|
finally
|
||||||
|
" Automatically forget about the job after it's done.
|
||||||
|
if has_key(s:job_map, l:job_id)
|
||||||
|
call remove(s:job_map, l:job_id)
|
||||||
|
endif
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:VimExitCallback(job, exit_code) abort
|
function! s:VimExitCallback(job, exit_code) abort
|
||||||
let l:job_id = ale#job#ParseVim8ProcessID(string(a:job))
|
let l:job_id = ale#job#ParseVim8ProcessID(string(a:job))
|
||||||
call ale#util#GetFunction(s:job_map[l:job_id].exit_cb)(l:job_id, a:exit_code)
|
let l:info = s:job_map[l:job_id]
|
||||||
|
let l:info.exit_code = a:exit_code
|
||||||
|
|
||||||
|
" The program can exit before the data has finished being read.
|
||||||
|
if ch_status(job_getchannel(a:job)) ==# 'closed'
|
||||||
|
try
|
||||||
|
call ale#util#GetFunction(l:info.exit_cb)(l:job_id, a:exit_code)
|
||||||
|
finally
|
||||||
|
" Automatically forget about the job after it's done.
|
||||||
|
if has_key(s:job_map, l:job_id)
|
||||||
|
call remove(s:job_map, l:job_id)
|
||||||
|
endif
|
||||||
|
endtry
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#job#ParseVim8ProcessID(job_string) abort
|
function! ale#job#ParseVim8ProcessID(job_string) abort
|
||||||
@ -94,6 +135,19 @@ function! ale#job#ValidateArguments(command, options) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale#job#PrepareCommand(command) abort
|
||||||
|
" The command will be executed in a subshell. This fixes a number of
|
||||||
|
" issues, including reading the PATH variables correctly, %PATHEXT%
|
||||||
|
" expansion on Windows, etc.
|
||||||
|
"
|
||||||
|
" NeoVim handles this issue automatically if the command is a String,
|
||||||
|
" but we'll do this explicitly, so we use thes same exact command for both
|
||||||
|
" versions.
|
||||||
|
return has('win32')
|
||||||
|
\ ? 'cmd /c ' . a:command
|
||||||
|
\ : split(&shell) + split(&shellcmdflag) + [a:command]
|
||||||
|
endfunction
|
||||||
|
|
||||||
" Start a job with options which are agnostic to Vim and NeoVim.
|
" Start a job with options which are agnostic to Vim and NeoVim.
|
||||||
"
|
"
|
||||||
" The following options are accepted:
|
" The following options are accepted:
|
||||||
|
Loading…
Reference in New Issue
Block a user