Simplify job cleanup code
This commit is contained in:
parent
a0e0408ecc
commit
3c5156d4a4
@ -104,6 +104,8 @@ function! ale#Lint(...) abort
|
|||||||
call filter(l:linters, '!v:val.lint_file')
|
call filter(l:linters, '!v:val.lint_file')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
call ale#engine#StopCurrentJobs(l:buffer, l:should_lint_file)
|
||||||
|
|
||||||
for l:linter in l:linters
|
for l:linter in l:linters
|
||||||
call ale#engine#Invoke(l:buffer, l:linter)
|
call ale#engine#Invoke(l:buffer, l:linter)
|
||||||
endfor
|
endfor
|
||||||
|
@ -6,9 +6,7 @@ function! ale#cleanup#Buffer(buffer) abort
|
|||||||
call ale#engine#RemoveManagedFiles(a:buffer)
|
call ale#engine#RemoveManagedFiles(a:buffer)
|
||||||
|
|
||||||
" When buffers are removed, clear all of the jobs.
|
" 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#StopCurrentJobs(a:buffer, 1)
|
||||||
call ale#engine#ClearJob(l:job)
|
|
||||||
endfor
|
|
||||||
|
|
||||||
" Clear delayed highlights for a buffer being removed.
|
" Clear delayed highlights for a buffer being removed.
|
||||||
if g:ale_set_highlights
|
if g:ale_set_highlights
|
||||||
|
@ -51,43 +51,6 @@ function! ale#engine#InitBufferInfo(buffer) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
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
|
" Register a temporary file to be managed with the ALE engine for
|
||||||
" a current job run.
|
" a current job run.
|
||||||
function! ale#engine#ManageFile(buffer, filename) abort
|
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)
|
call ale#history#SetExitCode(l:buffer, a:job_id, a:exit_code)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Call the same function for stopping jobs again to clean up the job
|
" Remove this job from the list.
|
||||||
" which just closed.
|
call ale#job#Stop(a:job_id)
|
||||||
call s:StopPreviousJobs(l:buffer, l:linter)
|
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
|
" Stop here if we land in the handle for a job completing if we're in
|
||||||
" a sandbox.
|
" a sandbox.
|
||||||
@ -507,10 +471,28 @@ function! s:InvokeChain(buffer, linter, chain_index, input) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#engine#Invoke(buffer, linter) abort
|
function! ale#engine#StopCurrentJobs(buffer, include_lint_file_jobs) abort
|
||||||
" Stop previous jobs for the same linter.
|
let l:info = get(g:ale_buffer_info, a:buffer, {})
|
||||||
call s:StopPreviousJobs(a:buffer, a:linter)
|
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')
|
let l:executable = has_key(a:linter, 'executable_callback')
|
||||||
\ ? ale#util#GetFunction(a:linter.executable_callback)(a:buffer)
|
\ ? ale#util#GetFunction(a:linter.executable_callback)(a:buffer)
|
||||||
\ : a:linter.executable
|
\ : a:linter.executable
|
||||||
|
@ -268,12 +268,16 @@ endfunction
|
|||||||
" Given a Job ID, stop that job.
|
" Given a Job ID, stop that job.
|
||||||
" Invalid job IDs will be ignored.
|
" Invalid job IDs will be ignored.
|
||||||
function! ale#job#Stop(job_id) abort
|
function! ale#job#Stop(job_id) abort
|
||||||
|
if !has_key(s:job_map, a:job_id)
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
if has('nvim')
|
if has('nvim')
|
||||||
" FIXME: NeoVim kills jobs on a timer, but will not kill any processes
|
" 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
|
" which are child processes on Unix. Some work needs to be done to
|
||||||
" kill child processes to stop long-running processes like pylint.
|
" kill child processes to stop long-running processes like pylint.
|
||||||
call jobstop(a:job_id)
|
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
|
let l:job = s:job_map[a:job_id].job
|
||||||
|
|
||||||
" We must close the channel for reading the buffer if it is open
|
" We must close the channel for reading the buffer if it is open
|
||||||
|
Loading…
Reference in New Issue
Block a user