Simplify job cleanup code
This commit is contained in:
parent
a0e0408ecc
commit
3c5156d4a4
4 changed files with 33 additions and 47 deletions
|
@ -104,6 +104,8 @@ function! ale#Lint(...) abort
|
|||
call filter(l:linters, '!v:val.lint_file')
|
||||
endif
|
||||
|
||||
call ale#engine#StopCurrentJobs(l:buffer, l:should_lint_file)
|
||||
|
||||
for l:linter in l:linters
|
||||
call ale#engine#Invoke(l:buffer, l:linter)
|
||||
endfor
|
||||
|
|
|
@ -6,9 +6,7 @@ function! ale#cleanup#Buffer(buffer) abort
|
|||
call ale#engine#RemoveManagedFiles(a:buffer)
|
||||
|
||||
" When buffers are removed, clear all of the jobs.
|
||||
for l:job in get(g:ale_buffer_info[a:buffer], 'job_list', [])
|
||||
call ale#engine#ClearJob(l:job)
|
||||
endfor
|
||||
call ale#engine#StopCurrentJobs(a:buffer, 1)
|
||||
|
||||
" Clear delayed highlights for a buffer being removed.
|
||||
if g:ale_set_highlights
|
||||
|
|
|
@ -51,43 +51,6 @@ function! ale#engine#InitBufferInfo(buffer) abort
|
|||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#engine#ClearJob(job_id) abort
|
||||
if get(g:, 'ale_run_synchronously') == 1
|
||||
call remove(s:job_info_map, a:job_id)
|
||||
|
||||
return
|
||||
endif
|
||||
|
||||
call ale#job#Stop(a:job_id)
|
||||
|
||||
if has_key(s:job_info_map, a:job_id)
|
||||
call remove(s:job_info_map, a:job_id)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:StopPreviousJobs(buffer, linter) abort
|
||||
if !has_key(g:ale_buffer_info, a:buffer)
|
||||
" Do nothing if we didn't run anything for the buffer.
|
||||
return
|
||||
endif
|
||||
|
||||
let l:new_job_list = []
|
||||
|
||||
for l:job_id in g:ale_buffer_info[a:buffer].job_list
|
||||
if has_key(s:job_info_map, l:job_id)
|
||||
\&& s:job_info_map[l:job_id].linter.name ==# a:linter.name
|
||||
" Stop jobs which match the buffer and linter.
|
||||
call ale#engine#ClearJob(l:job_id)
|
||||
else
|
||||
" Keep other jobs in the list.
|
||||
call add(l:new_job_list, l:job_id)
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Update the list, removing the previously run job.
|
||||
let g:ale_buffer_info[a:buffer].job_list = l:new_job_list
|
||||
endfunction
|
||||
|
||||
" Register a temporary file to be managed with the ALE engine for
|
||||
" a current job run.
|
||||
function! ale#engine#ManageFile(buffer, filename) abort
|
||||
|
@ -160,9 +123,10 @@ function! s:HandleExit(job_id, exit_code) abort
|
|||
call ale#history#SetExitCode(l:buffer, a:job_id, a:exit_code)
|
||||
endif
|
||||
|
||||
" Call the same function for stopping jobs again to clean up the job
|
||||
" which just closed.
|
||||
call s:StopPreviousJobs(l:buffer, l:linter)
|
||||
" Remove this job from the list.
|
||||
call ale#job#Stop(a:job_id)
|
||||
call remove(s:job_info_map, a:job_id)
|
||||
call filter(g:ale_buffer_info[l:buffer].job_list, 'v:val !=# a:job_id')
|
||||
|
||||
" Stop here if we land in the handle for a job completing if we're in
|
||||
" a sandbox.
|
||||
|
@ -507,10 +471,28 @@ function! s:InvokeChain(buffer, linter, chain_index, input) abort
|
|||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#engine#Invoke(buffer, linter) abort
|
||||
" Stop previous jobs for the same linter.
|
||||
call s:StopPreviousJobs(a:buffer, a:linter)
|
||||
function! ale#engine#StopCurrentJobs(buffer, include_lint_file_jobs) abort
|
||||
let l:info = get(g:ale_buffer_info, a:buffer, {})
|
||||
let l:new_job_list = []
|
||||
|
||||
for l:job_id in get(l:info, 'job_list', [])
|
||||
let l:job_info = get(s:job_info_map, l:job_id, {})
|
||||
|
||||
if !empty(l:job_info)
|
||||
if a:include_lint_file_jobs || !l:job_info.linter.lint_file
|
||||
call ale#job#Stop(l:job_id)
|
||||
call remove(s:job_info_map, l:job_id)
|
||||
else
|
||||
call add(l:new_job_list, l:job_id)
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Update the List, so it includes only the jobs we still need.
|
||||
let l:info.job_list = l:new_job_list
|
||||
endfunction
|
||||
|
||||
function! ale#engine#Invoke(buffer, linter) abort
|
||||
let l:executable = has_key(a:linter, 'executable_callback')
|
||||
\ ? ale#util#GetFunction(a:linter.executable_callback)(a:buffer)
|
||||
\ : a:linter.executable
|
||||
|
|
|
@ -268,12 +268,16 @@ endfunction
|
|||
" Given a Job ID, stop that job.
|
||||
" Invalid job IDs will be ignored.
|
||||
function! ale#job#Stop(job_id) abort
|
||||
if !has_key(s:job_map, a:job_id)
|
||||
return
|
||||
endif
|
||||
|
||||
if has('nvim')
|
||||
" FIXME: NeoVim kills jobs on a timer, but will not kill any processes
|
||||
" which are child processes on Unix. Some work needs to be done to
|
||||
" kill child processes to stop long-running processes like pylint.
|
||||
call jobstop(a:job_id)
|
||||
elseif has_key(s:job_map, a:job_id)
|
||||
else
|
||||
let l:job = s:job_map[a:job_id].job
|
||||
|
||||
" We must close the channel for reading the buffer if it is open
|
||||
|
|
Reference in a new issue