#446 Fix g:ale_lint_on_text_changed compatibility issues

This commit is contained in:
w0rp 2017-04-03 19:04:02 +01:00
parent 927ee79026
commit b7c79974bb
2 changed files with 44 additions and 51 deletions

View File

@ -155,14 +155,17 @@ let g:ale_history_enabled = get(g:, 'ale_history_enabled', 1)
let g:ale_history_log_output = get(g:, 'ale_history_log_output', 0) let g:ale_history_log_output = get(g:, 'ale_history_log_output', 0)
function! ALEInitAuGroups() abort function! ALEInitAuGroups() abort
" This value used to be a Boolean as a Number, and is now a String.
let l:text_changed = '' . g:ale_lint_on_text_changed
augroup ALERunOnTextChangedGroup augroup ALERunOnTextChangedGroup
autocmd! autocmd!
if g:ale_enabled if g:ale_enabled
if g:ale_lint_on_text_changed ==? 'always' || g:ale_lint_on_text_changed == 1 if l:text_changed ==? 'always' || l:text_changed ==# '1'
autocmd TextChanged,TextChangedI * call ale#Queue(g:ale_lint_delay) autocmd TextChanged,TextChangedI * call ale#Queue(g:ale_lint_delay)
elseif g:ale_lint_on_text_changed ==? 'normal' elseif l:text_changed ==? 'normal'
autocmd TextChanged * call ale#Queue(g:ale_lint_delay) autocmd TextChanged * call ale#Queue(g:ale_lint_delay)
elseif g:ale_lint_on_text_changed ==? 'insert' elseif l:text_changed ==? 'insert'
autocmd TextChangedI * call ale#Queue(g:ale_lint_delay) autocmd TextChangedI * call ale#Queue(g:ale_lint_delay)
endif endif
endif endif

View File

@ -1,66 +1,56 @@
Before: Before:
function! CheckAutocmd(group)
call ALEInitAuGroups()
redir => l:output
execute 'silent autocmd ' . a:group
redir END
return map(
\ filter(split(l:output, "\n"), 'v:val =~# ''^ALE'''),
\ 'split(v:val)[1]'
\)
endfunction
Save g:ale_lint_on_text_changed Save g:ale_lint_on_text_changed
Save g:ale_lint_on_insert_leave Save g:ale_lint_on_insert_leave
autocmd!
After: After:
Restore g:ale_lint_on_text_changed delfunction CheckAutocmd
Restore g:ale_lint_on_insert_leave Restore
unlet! g:output
unlet! g:expected_autocmd
autocmd!
Execute (ALE should bind to TextChanged events when g:ale_lint_on_text_changed = 1): call ALEInitAuGroups()
let g:expected_autocmd = join([
\ '',
\ '--- Auto-Commands ---',
\ 'ALERunOnTextChangedGroup TextChanged',
\ ' * call ale#Queue(g:ale_lint_delay)',
\ 'ALERunOnTextChangedGroup TextChangedI',
\ ' * call ale#Queue(g:ale_lint_delay)',
\], "\n")
Execute (g:ale_lint_on_text_changed = 0 should bind no events):
let g:ale_lint_on_text_changed = 0
AssertEqual [], CheckAutocmd('ALERunOnTextChangedGroup')
Execute (g:ale_lint_on_text_changed = 1 bind both events):
let g:ale_lint_on_text_changed = 1 let g:ale_lint_on_text_changed = 1
call ALEInitAuGroups()
redir => g:output AssertEqual ['TextChanged', 'TextChangedI'], CheckAutocmd('ALERunOnTextChangedGroup')
autocmd ALERunOnTextChangedGroup TextChanged,TextChangedI *
redir END
AssertEqual g:expected_autocmd, g:output
Execute (ALE should bind to TextChanged events when g:ale_lint_on_text_changed = 'always'):
let g:expected_autocmd = join([
\ '',
\ '--- Auto-Commands ---',
\ 'ALERunOnTextChangedGroup TextChanged',
\ ' * call ale#Queue(g:ale_lint_delay)',
\ 'ALERunOnTextChangedGroup TextChangedI',
\ ' * call ale#Queue(g:ale_lint_delay)',
\], "\n")
Execute (g:ale_lint_on_text_changed = 'always' should bind both events):
let g:ale_lint_on_text_changed = 'always' let g:ale_lint_on_text_changed = 'always'
call ALEInitAuGroups()
redir => g:output AssertEqual ['TextChanged', 'TextChangedI'], CheckAutocmd('ALERunOnTextChangedGroup')
autocmd ALERunOnTextChangedGroup TextChanged,TextChangedI *
redir END
AssertEqual g:expected_autocmd, g:output Execute (g:ale_lint_on_text_changed = 'normal' should bind only TextChanged):
let g:ale_lint_on_text_changed = 'normal'
Execute (ALE should bind to InsertLeave event when g:ale_lint_on_insert_leave = 1): AssertEqual ['TextChanged'], CheckAutocmd('ALERunOnTextChangedGroup')
let g:expected_autocmd = join([
\ "",
\ "--- Auto-Commands ---",
\ "ALERunOnInsertLeave InsertLeave",
\ " * call ale#Queue(0, 'lint_file')",
\], "\n")
Execute (g:ale_lint_on_text_changed = 'insert' should bind only TextChangedI):
let g:ale_lint_on_text_changed = 'insert'
AssertEqual ['TextChangedI'], CheckAutocmd('ALERunOnTextChangedGroup')
Execute (g:ale_lint_on_insert_leave = 1 should bind InsertLeave):
let g:ale_lint_on_insert_leave = 1 let g:ale_lint_on_insert_leave = 1
call ALEInitAuGroups()
redir => g:output AssertEqual ['InsertLeave'], CheckAutocmd('ALERunOnInsertLeave')
autocmd ALERunOnInsertLeave InsertLeave *
redir END
AssertEqual g:expected_autocmd, g:output Execute (g:ale_lint_on_insert_leave = 0 should bind no events):
let g:ale_lint_on_insert_leave = 0
AssertEqual [], CheckAutocmd('ALERunOnInsertLeave')