summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-06-06 16:44:01 +0100
committerw0rp <devw0rp@gmail.com>2017-06-06 16:44:01 +0100
commit3c5156d4a4e700adae32866b5978a941199ade2a (patch)
treeeff82dc1640fe4a5dcc36cea1de131a6b44b3854
parenta0e0408ecc39d0fc7b8b66ac39c2dc5e7805e787 (diff)
downloadale-3c5156d4a4e700adae32866b5978a941199ade2a.zip
Simplify job cleanup code
-rw-r--r--autoload/ale.vim2
-rw-r--r--autoload/ale/cleanup.vim4
-rw-r--r--autoload/ale/engine.vim68
-rw-r--r--autoload/ale/job.vim6
4 files changed, 33 insertions, 47 deletions
diff --git a/autoload/ale.vim b/autoload/ale.vim
index 9751225b..9147b3a5 100644
--- a/autoload/ale.vim
+++ b/autoload/ale.vim
@@ -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
diff --git a/autoload/ale/cleanup.vim b/autoload/ale/cleanup.vim
index 8b6494ef..4701b960 100644
--- a/autoload/ale/cleanup.vim
+++ b/autoload/ale/cleanup.vim
@@ -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
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim
index a99eccca..944aab3a 100644
--- a/autoload/ale/engine.vim
+++ b/autoload/ale/engine.vim
@@ -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
diff --git a/autoload/ale/job.vim b/autoload/ale/job.vim
index 52789bb5..f4dc1252 100644
--- a/autoload/ale/job.vim
+++ b/autoload/ale/job.vim
@@ -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