#333 Change arguments for ale#Queue so they are more obvious, and check files in more places

This commit is contained in:
w0rp 2017-03-21 13:38:27 +00:00
parent 2d1d6fb850
commit 3e13e10e03
3 changed files with 18 additions and 15 deletions

View File

@ -14,16 +14,17 @@ function! ale#ShouldDoNothing() abort
\ || ale#util#InSandbox() \ || ale#util#InSandbox()
endfunction endfunction
" (delay, [run_file_linters]) " (delay, [linting_flag])
function! ale#Queue(delay, ...) abort function! ale#Queue(delay, ...) abort
if len(a:0) > 1 if len(a:0) > 1
throw 'too many arguments!' throw 'too many arguments!'
endif endif
let l:a1 = len(a:0) > 1 ? a:1 : 0 " Default run_file_linters to 0
let l:linting_flag = len(a:0) > 1 ? a:1 : ''
if type(l:a1) != type(1) || (l:a1 != 0 && l:a1 != 1) if l:linting_flag !=# '' && l:linting_flag !=# 'lint_file'
throw 'The lint_file argument must be a Number which is either 0 or 1!' throw "linting_flag must be either '' or 'lint_file'"
endif endif
if ale#ShouldDoNothing() if ale#ShouldDoNothing()
@ -31,7 +32,7 @@ function! ale#Queue(delay, ...) abort
endif endif
" Remember the event used for linting. " Remember the event used for linting.
let s:should_lint_file = l:a1 let s:should_lint_file = l:linting_flag ==# 'lint_file'
if s:lint_timer != -1 if s:lint_timer != -1
call timer_stop(s:lint_timer) call timer_stop(s:lint_timer)

View File

@ -1168,6 +1168,9 @@ ALELint *ALELint*
Run ALE once for the current buffer. This command can be used to run ALE Run ALE once for the current buffer. This command can be used to run ALE
manually, instead of automatically, if desired. manually, instead of automatically, if desired.
This command will also run linters where `lint_file` is set to `1`, or in
other words linters which check the file instead of the Vim buffer.
A plug mapping `<Plug>(ale_lint)` is defined for this command. A plug mapping `<Plug>(ale_lint)` is defined for this command.
@ -1219,17 +1222,16 @@ ALEDetail *ALEDetail*
=============================================================================== ===============================================================================
7. API *ale-api* 7. API *ale-api*
ale#Queue(delay, [run_file_linters]) *ale#Queue()* ale#Queue(delay, [linting_flag]) *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` An optional `linting_flag` argument can be given. If `linting_flag`
is `0`, then no linters where the `lint_file` option is set to `1` will be is `'lint_file'`, then 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 run. Linters with `lint_file` set to `1` are not run by default.
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, 1) autocmd BufEnter,BufRead * call ale#Queue(300, 'lint_file')
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, 1) autocmd BufWrite * call ale#Queue(0, 'lint_file')
endif endif
augroup END augroup END
@ -191,8 +191,8 @@ function! s:ALEToggle() abort
let g:ale_enabled = !get(g:, 'ale_enabled') let g:ale_enabled = !get(g:, 'ale_enabled')
if g:ale_enabled if g:ale_enabled
" Lint immediately " Lint immediately, including running linters against the file.
call ale#Queue(0) call ale#Queue(0, 'lint_file')
else else
" Make sure the buffer number is a number, not a string, " Make sure the buffer number is a number, not a string,
" otherwise things can go wrong. " otherwise things can go wrong.
@ -226,7 +226,7 @@ command! ALEDetail :call ale#cursor#ShowCursorDetail()
" A command for turning ALE on or off. " A command for turning ALE on or off.
command! ALEToggle :call s:ALEToggle() command! ALEToggle :call s:ALEToggle()
" A command for linting manually. " A command for linting manually.
command! ALELint :call ale#Queue(0) command! ALELint :call ale#Queue(0, 'lint_file')
" Define a command to get information about current filetype. " Define a command to get information about current filetype.
command! ALEInfo :call ale#debugging#Info() command! ALEInfo :call ale#debugging#Info()