#904 - Allow linting to run on save a second after :q fails
This commit is contained in:
parent
5946a128c3
commit
81d993086e
@ -2,21 +2,26 @@
|
|||||||
|
|
||||||
function! ale#events#QuitEvent(buffer) abort
|
function! ale#events#QuitEvent(buffer) abort
|
||||||
" Remember when ALE is quitting for BufWrite, etc.
|
" Remember when ALE is quitting for BufWrite, etc.
|
||||||
call setbufvar(a:buffer, 'ale_quitting', 1)
|
call setbufvar(a:buffer, 'ale_quitting', ale#util#ClockMilliseconds())
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! ale#events#QuitRecently(buffer) abort
|
||||||
|
let l:time = getbufvar(a:buffer, 'ale_quitting', 0)
|
||||||
|
|
||||||
|
return l:time && ale#util#ClockMilliseconds() - l:time < 1000
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#events#SaveEvent(buffer) abort
|
function! ale#events#SaveEvent(buffer) abort
|
||||||
call setbufvar(a:buffer, 'ale_save_event_fired', 1)
|
call setbufvar(a:buffer, 'ale_save_event_fired', 1)
|
||||||
let l:should_lint = ale#Var(a:buffer, 'enabled')
|
let l:should_lint = ale#Var(a:buffer, 'enabled')
|
||||||
\ && g:ale_lint_on_save
|
\ && g:ale_lint_on_save
|
||||||
\ && !getbufvar(a:buffer, 'ale_quitting')
|
|
||||||
|
|
||||||
if g:ale_fix_on_save
|
if g:ale_fix_on_save
|
||||||
let l:will_fix = ale#fix#Fix('save_file')
|
let l:will_fix = ale#fix#Fix('save_file')
|
||||||
let l:should_lint = l:should_lint && !l:will_fix
|
let l:should_lint = l:should_lint && !l:will_fix
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if l:should_lint
|
if l:should_lint && !ale#events#QuitRecently(a:buffer)
|
||||||
call ale#Queue(0, 'lint_file', a:buffer)
|
call ale#Queue(0, 'lint_file', a:buffer)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -58,7 +58,7 @@ function! ale#fix#ApplyQueuedFixes() abort
|
|||||||
" fixing problems.
|
" fixing problems.
|
||||||
if g:ale_enabled
|
if g:ale_enabled
|
||||||
\&& l:should_lint
|
\&& l:should_lint
|
||||||
\&& !getbufvar(l:buffer, 'ale_quitting')
|
\&& !ale#events#QuitRecently(l:buffer)
|
||||||
call ale#Queue(0, l:data.should_save ? 'lint_file' : '')
|
call ale#Queue(0, l:data.should_save ? 'lint_file' : '')
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
@ -55,6 +55,19 @@ Execute(No linting should be done on :wq or :x):
|
|||||||
|
|
||||||
AssertEqual [], getloclist(0)
|
AssertEqual [], getloclist(0)
|
||||||
|
|
||||||
|
Execute(No linting should be for :w after :q fails):
|
||||||
|
let g:ale_lint_on_save = 1
|
||||||
|
let g:ale_fix_on_save = 0
|
||||||
|
|
||||||
|
call ale#events#QuitEvent(bufnr(''))
|
||||||
|
|
||||||
|
" Simulate 2 seconds passing.
|
||||||
|
let b:ale_quitting -= 1000
|
||||||
|
|
||||||
|
call ale#events#SaveEvent(bufnr(''))
|
||||||
|
|
||||||
|
AssertEqual 1, len(getloclist(0))
|
||||||
|
|
||||||
Execute(No linting should be done on :wq or :x after fixing files):
|
Execute(No linting should be done on :wq or :x after fixing files):
|
||||||
let g:ale_lint_on_save = 0
|
let g:ale_lint_on_save = 0
|
||||||
let g:ale_fix_on_save = 1
|
let g:ale_fix_on_save = 1
|
||||||
@ -69,3 +82,16 @@ Execute(No linting should be done on :wq or :x after fixing files):
|
|||||||
call ale#events#SaveEvent(bufnr(''))
|
call ale#events#SaveEvent(bufnr(''))
|
||||||
|
|
||||||
AssertEqual [], getloclist(0)
|
AssertEqual [], getloclist(0)
|
||||||
|
|
||||||
|
Execute(Linting should be done after :q fails and fixing files):
|
||||||
|
let g:ale_lint_on_save = 0
|
||||||
|
let g:ale_fix_on_save = 1
|
||||||
|
|
||||||
|
call ale#events#QuitEvent(bufnr(''))
|
||||||
|
|
||||||
|
" Simulate 2 seconds passing.
|
||||||
|
let b:ale_quitting -= 1000
|
||||||
|
|
||||||
|
call ale#events#SaveEvent(bufnr(''))
|
||||||
|
|
||||||
|
AssertEqual 1, len(getloclist(0))
|
||||||
|
@ -8,11 +8,15 @@ After:
|
|||||||
Restore
|
Restore
|
||||||
|
|
||||||
unlet! b:ale_quitting
|
unlet! b:ale_quitting
|
||||||
|
unlet! b:time_before
|
||||||
|
|
||||||
|
Execute(QuitEvent should set b:ale_quitting some time from the clock):
|
||||||
|
let b:time_before = ale#util#ClockMilliseconds()
|
||||||
|
|
||||||
Execute(QuitEvent should set b:ale_quitting to 1):
|
|
||||||
call ale#events#QuitEvent(bufnr(''))
|
call ale#events#QuitEvent(bufnr(''))
|
||||||
|
|
||||||
AssertEqual 1, b:ale_quitting
|
Assert b:ale_quitting >= b:time_before
|
||||||
|
Assert b:ale_quitting <= ale#util#ClockMilliseconds()
|
||||||
|
|
||||||
Execute(EnterEvent should set b:ale_quitting to 0):
|
Execute(EnterEvent should set b:ale_quitting to 0):
|
||||||
let b:ale_quitting = 1
|
let b:ale_quitting = 1
|
||||||
@ -20,3 +24,16 @@ Execute(EnterEvent should set b:ale_quitting to 0):
|
|||||||
call ale#events#EnterEvent(bufnr(''))
|
call ale#events#EnterEvent(bufnr(''))
|
||||||
|
|
||||||
AssertEqual 0, b:ale_quitting
|
AssertEqual 0, b:ale_quitting
|
||||||
|
|
||||||
|
Execute(The QuitRecently function should work when the variable isn't set):
|
||||||
|
AssertEqual 0, ale#events#QuitRecently(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The QuitRecently function should return 1 when ALE quit recently):
|
||||||
|
let b:ale_quitting = ale#util#ClockMilliseconds()
|
||||||
|
|
||||||
|
AssertEqual 1, ale#events#QuitRecently(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The QuitRecently function should return 0 when a second has passed):
|
||||||
|
let b:ale_quitting = ale#util#ClockMilliseconds() - 1001
|
||||||
|
|
||||||
|
AssertEqual 0, ale#events#QuitRecently(bufnr(''))
|
||||||
|
Loading…
Reference in New Issue
Block a user