From e7d32fe37677636a0be087163c1efa7d0ba10d47 Mon Sep 17 00:00:00 2001 From: w0rp Date: Tue, 14 Mar 2017 23:51:57 +0000 Subject: [PATCH] #333 Pass in a flag indicating that linters should be run against files, and clear more jobs --- autoload/ale.vim | 29 ++++++++++++++++------------- autoload/ale/engine.vim | 10 +++++++++- doc/ale.txt | 8 +++++++- plugin/ale.vim | 4 ++-- 4 files changed, 34 insertions(+), 17 deletions(-) diff --git a/autoload/ale.vim b/autoload/ale.vim index c81a57a..2d29c8f 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -3,6 +3,7 @@ " Manages execution of linters when requested by autocommands let s:lint_timer = -1 +let s:should_lint_file = 0 " A function for checking various conditions whereby ALE just shouldn't " attempt to do anything, say if particular buffer types are open in Vim. @@ -13,11 +14,25 @@ function! ale#ShouldDoNothing() abort \ || ale#util#InSandbox() 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() return endif + " Remember the event used for linting. + let s:should_lint_file = l:a1 + if s:lint_timer != -1 call timer_stop(s:lint_timer) let s:lint_timer = -1 @@ -51,18 +66,6 @@ function! ale#Lint(...) abort let g:ale_buffer_info[l:buffer].new_loclist = [] 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) endfor endfunction diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 31591de..8f5a06a 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -626,7 +626,15 @@ endfunction function! ale#engine#Invoke(buffer, linter) abort " Stop previous jobs for the same 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 " Given a buffer number, return the warnings and errors for a given buffer. diff --git a/doc/ale.txt b/doc/ale.txt index b6e7a10..e4b458f 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -1218,12 +1218,18 @@ ALEDetail *ALEDetail* =============================================================================== 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, 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 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()* diff --git a/plugin/ale.vim b/plugin/ale.vim index 8fa0093..84f57db 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -157,14 +157,14 @@ function! s:ALEInitAuGroups() abort augroup ALERunOnEnterGroup autocmd! 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 augroup END augroup ALERunOnSaveGroup autocmd! if g:ale_enabled && g:ale_lint_on_save - autocmd BufWrite * call ale#Queue(0) + autocmd BufWrite * call ale#Queue(0, 1) endif augroup END