#333 Pass in a flag indicating that linters should be run against files, and clear more jobs

This commit is contained in:
w0rp 2017-03-14 23:51:57 +00:00
parent 790c614b7a
commit e7d32fe376
4 changed files with 34 additions and 17 deletions

View File

@ -3,6 +3,7 @@
" Manages execution of linters when requested by autocommands " Manages execution of linters when requested by autocommands
let s:lint_timer = -1 let s:lint_timer = -1
let s:should_lint_file = 0
" A function for checking various conditions whereby ALE just shouldn't " A function for checking various conditions whereby ALE just shouldn't
" attempt to do anything, say if particular buffer types are open in Vim. " attempt to do anything, say if particular buffer types are open in Vim.
@ -13,11 +14,25 @@ function! ale#ShouldDoNothing() abort
\ || ale#util#InSandbox() \ || ale#util#InSandbox()
endfunction endfunction
function! ale#Queue(delay) abort " (delay, [run_file_linters])
function! ale#Queue(delay, ...) abort
if len(a:0) > 1
throw 'too many arguments!'
endif
let l:a1 = len(a:0) > 1 ? a:1 : 0
if type(l:a1) != type(1) || (l:a1 != 0 && l:a1 != 1)
throw 'The lint_file argument must be a Number which is either 0 or 1!'
endif
if ale#ShouldDoNothing() if ale#ShouldDoNothing()
return return
endif endif
" Remember the event used for linting.
let s:should_lint_file = l:a1
if s:lint_timer != -1 if s:lint_timer != -1
call timer_stop(s:lint_timer) call timer_stop(s:lint_timer)
let s:lint_timer = -1 let s:lint_timer = -1
@ -51,18 +66,6 @@ function! ale#Lint(...) abort
let g:ale_buffer_info[l:buffer].new_loclist = [] let g:ale_buffer_info[l:buffer].new_loclist = []
for l:linter in l:linters for l:linter in l:linters
" Check if a given linter has a program which can be executed.
if has_key(l:linter, 'executable_callback')
let l:executable = ale#util#GetFunction(l:linter.executable_callback)(l:buffer)
else
let l:executable = l:linter.executable
endif
if !executable(l:executable)
" The linter's program cannot be executed, so skip it.
continue
endif
call ale#engine#Invoke(l:buffer, l:linter) call ale#engine#Invoke(l:buffer, l:linter)
endfor endfor
endfunction endfunction

View File

@ -626,7 +626,15 @@ endfunction
function! ale#engine#Invoke(buffer, linter) abort function! ale#engine#Invoke(buffer, linter) abort
" Stop previous jobs for the same linter. " Stop previous jobs for the same linter.
call s:StopPreviousJobs(a:buffer, a:linter) call s:StopPreviousJobs(a:buffer, a:linter)
call s:InvokeChain(a:buffer, a:linter, 0, [])
let l:executable = has_key(a:linter, 'executable_callback')
\ ? ale#util#GetFunction(a:linter.executable_callback)(a:buffer)
\ : a:linter.executable
" Run this program if it can be executed.
if executable(l:executable)
call s:InvokeChain(a:buffer, a:linter, 0, [])
endif
endfunction endfunction
" Given a buffer number, return the warnings and errors for a given buffer. " Given a buffer number, return the warnings and errors for a given buffer.

View File

@ -1218,12 +1218,18 @@ ALEDetail *ALEDetail*
=============================================================================== ===============================================================================
7. API *ale-api* 7. API *ale-api*
ale#Queue(delay) *ale#Queue()* ale#Queue(delay, [run_file_linters]) *ale#Queue()*
Run linters for the current buffer, based on the filetype of the buffer, Run linters for the current buffer, based on the filetype of the buffer,
with a given `delay`. A `delay` of `0` will run the linters immediately. with a given `delay`. A `delay` of `0` will run the linters immediately.
The linters will always be run in the background. Calling this function The linters will always be run in the background. Calling this function
again from the same buffer again from the same buffer
An optional `run_file_linters` argument can be given. If `run_file_linters`
is `0`, then no linters where the `lint_file` option is set to `1` will be
run. If `run_file_linters` is set to `1`, then all linters for the current
file will be run. `run_file_linters` defaults to `0`.
ale#engine#EscapeCommandPart(command_part) *ale#engine#EscapeCommandPart()* ale#engine#EscapeCommandPart(command_part) *ale#engine#EscapeCommandPart()*

View File

@ -157,14 +157,14 @@ function! s:ALEInitAuGroups() abort
augroup ALERunOnEnterGroup augroup ALERunOnEnterGroup
autocmd! autocmd!
if g:ale_enabled && g:ale_lint_on_enter if g:ale_enabled && g:ale_lint_on_enter
autocmd BufEnter,BufRead * call ale#Queue(300) autocmd BufEnter,BufRead * call ale#Queue(300, 1)
endif endif
augroup END augroup END
augroup ALERunOnSaveGroup augroup ALERunOnSaveGroup
autocmd! autocmd!
if g:ale_enabled && g:ale_lint_on_save if g:ale_enabled && g:ale_lint_on_save
autocmd BufWrite * call ale#Queue(0) autocmd BufWrite * call ale#Queue(0, 1)
endif endif
augroup END augroup END