Set up most of the autocmd events in one group
This commit is contained in:
parent
9674132933
commit
0e1528ec34
@ -83,13 +83,13 @@ function! ale#events#Init() 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 ALEPatternOptionsGroup
|
||||
augroup ALEEvents
|
||||
autocmd!
|
||||
autocmd BufEnter,BufRead * call ale#pattern_options#SetOptions(str2nr(expand('<abuf>')))
|
||||
augroup END
|
||||
|
||||
augroup ALERunOnTextChangedGroup
|
||||
autocmd!
|
||||
" These events always need to be set up.
|
||||
autocmd BufEnter,BufRead * call ale#pattern_options#SetOptions(str2nr(expand('<abuf>')))
|
||||
autocmd BufWritePost * call ale#events#SaveEvent(str2nr(expand('<abuf>')))
|
||||
|
||||
if g:ale_enabled
|
||||
if l:text_changed is? 'always' || l:text_changed is# '1'
|
||||
autocmd TextChanged,TextChangedI * call ale#Queue(g:ale_lint_delay)
|
||||
@ -98,61 +98,36 @@ function! ale#events#Init() abort
|
||||
elseif l:text_changed is? 'insert'
|
||||
autocmd TextChangedI * call ale#Queue(g:ale_lint_delay)
|
||||
endif
|
||||
endif
|
||||
augroup END
|
||||
|
||||
augroup ALERunOnEnterGroup
|
||||
autocmd!
|
||||
if g:ale_enabled
|
||||
" Handle everything that needs to happen when buffers are entered.
|
||||
autocmd BufEnter * call ale#events#EnterEvent(str2nr(expand('<abuf>')))
|
||||
endif
|
||||
if g:ale_enabled && g:ale_lint_on_enter
|
||||
autocmd BufWinEnter,BufRead * call ale#Queue(0, 'lint_file', str2nr(expand('<abuf>')))
|
||||
" Track when the file is changed outside of Vim.
|
||||
autocmd FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand('<abuf>')))
|
||||
|
||||
if g:ale_lint_on_enter
|
||||
autocmd BufWinEnter,BufRead * call ale#Queue(0, 'lint_file', str2nr(expand('<abuf>')))
|
||||
" Track when the file is changed outside of Vim.
|
||||
autocmd FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand('<abuf>')))
|
||||
endif
|
||||
|
||||
if g:ale_lint_on_filetype_changed
|
||||
" Only start linting if the FileType actually changes after
|
||||
" opening a buffer. The FileType will fire when buffers are opened.
|
||||
autocmd FileType * call ale#events#FileTypeEvent(
|
||||
\ str2nr(expand('<abuf>')),
|
||||
\ expand('<amatch>')
|
||||
\)
|
||||
endif
|
||||
|
||||
if g:ale_lint_on_insert_leave
|
||||
autocmd InsertLeave * call ale#Queue(0)
|
||||
endif
|
||||
|
||||
if g:ale_echo_cursor
|
||||
autocmd CursorMoved,CursorHold * call ale#cursor#EchoCursorWarningWithDelay()
|
||||
" Look for a warning to echo as soon as we leave Insert mode.
|
||||
" The script's position variable used when moving the cursor will
|
||||
" not be changed here.
|
||||
autocmd InsertLeave * call ale#cursor#EchoCursorWarning()
|
||||
endif
|
||||
endif
|
||||
augroup END
|
||||
|
||||
augroup ALERunOnFiletypeChangeGroup
|
||||
autocmd!
|
||||
if g:ale_enabled && g:ale_lint_on_filetype_changed
|
||||
" Only start linting if the FileType actually changes after
|
||||
" opening a buffer. The FileType will fire when buffers are opened.
|
||||
autocmd FileType * call ale#events#FileTypeEvent(
|
||||
\ str2nr(expand('<abuf>')),
|
||||
\ expand('<amatch>')
|
||||
\)
|
||||
endif
|
||||
augroup END
|
||||
|
||||
augroup ALERunOnSaveGroup
|
||||
autocmd!
|
||||
autocmd BufWritePost * call ale#events#SaveEvent(str2nr(expand('<abuf>')))
|
||||
augroup END
|
||||
|
||||
augroup ALERunOnInsertLeave
|
||||
autocmd!
|
||||
if g:ale_enabled && g:ale_lint_on_insert_leave
|
||||
autocmd InsertLeave * call ale#Queue(0)
|
||||
endif
|
||||
augroup END
|
||||
|
||||
augroup ALECursorGroup
|
||||
autocmd!
|
||||
if g:ale_enabled && g:ale_echo_cursor
|
||||
autocmd CursorMoved,CursorHold * call ale#cursor#EchoCursorWarningWithDelay()
|
||||
" Look for a warning to echo as soon as we leave Insert mode.
|
||||
" The script's position variable used when moving the cursor will
|
||||
" not be changed here.
|
||||
autocmd InsertLeave * call ale#cursor#EchoCursorWarning()
|
||||
endif
|
||||
augroup END
|
||||
|
||||
if !g:ale_enabled
|
||||
augroup! ALERunOnTextChangedGroup
|
||||
augroup! ALERunOnEnterGroup
|
||||
augroup! ALERunOnInsertLeave
|
||||
augroup! ALECursorGroup
|
||||
endif
|
||||
endfunction
|
||||
|
@ -32,12 +32,8 @@ Before:
|
||||
\}]
|
||||
let g:expected_groups = [
|
||||
\ 'ALECleanupGroup',
|
||||
\ 'ALECursorGroup',
|
||||
\ 'ALEEvents',
|
||||
\ 'ALEHighlightBufferGroup',
|
||||
\ 'ALERunOnEnterGroup',
|
||||
\ 'ALERunOnFiletypeChangeGroup',
|
||||
\ 'ALERunOnSaveGroup',
|
||||
\ 'ALERunOnTextChangedGroup',
|
||||
\]
|
||||
|
||||
function! ToggleTestCallback(buffer, output)
|
||||
@ -60,7 +56,7 @@ Before:
|
||||
let l:results = []
|
||||
|
||||
for l:line in split(l:output, "\n")
|
||||
let l:match = matchlist(l:line, '^ALE[a-zA-Z]\+Group')
|
||||
let l:match = matchlist(l:line, '^ALE[a-zA-Z]\+')
|
||||
|
||||
" We don't care about some groups here.
|
||||
if !empty(l:match)
|
||||
@ -139,13 +135,7 @@ Execute(ALEToggle should reset everything and then run again):
|
||||
AssertEqual [], getloclist(0), 'The loclist was not cleared'
|
||||
AssertEqual [0, []], ale#sign#FindCurrentSigns(bufnr('%')), 'The signs were not cleared'
|
||||
AssertEqual [], getmatches(), 'The highlights were not cleared'
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 'ALECleanupGroup',
|
||||
\ 'ALEHighlightBufferGroup',
|
||||
\ 'ALERunOnSaveGroup',
|
||||
\ ],
|
||||
\ ParseAuGroups()
|
||||
AssertEqual g:expected_groups, ParseAuGroups()
|
||||
|
||||
" Toggle ALE on, everything should be set up and run again.
|
||||
ALEToggle
|
||||
|
@ -26,8 +26,9 @@ Before:
|
||||
" for the one matching the current buffer.
|
||||
if l:line =~# '<buffer=' . bufnr('') . '>'
|
||||
let l:header .= ' <buffer>'
|
||||
else
|
||||
elseif l:line[:0] is# ' '
|
||||
call add(l:matches, join(split(l:header . l:line)))
|
||||
else
|
||||
let l:header = ''
|
||||
endif
|
||||
endif
|
||||
@ -38,16 +39,28 @@ Before:
|
||||
return l:matches
|
||||
endfunction
|
||||
|
||||
Save g:ale_completion_enabled
|
||||
Save g:ale_echo_cursor
|
||||
Save g:ale_enabled
|
||||
Save g:ale_lint_on_text_changed
|
||||
Save g:ale_lint_on_insert_leave
|
||||
Save g:ale_pattern_options_enabled
|
||||
Save g:ale_fix_on_save
|
||||
Save g:ale_lint_on_enter
|
||||
Save g:ale_lint_on_filetype_changed
|
||||
Save g:ale_lint_on_insert_leave
|
||||
Save g:ale_lint_on_save
|
||||
Save g:ale_echo_cursor
|
||||
Save g:ale_fix_on_save
|
||||
Save g:ale_completion_enabled
|
||||
Save g:ale_lint_on_text_changed
|
||||
Save g:ale_pattern_options_enabled
|
||||
|
||||
" Turn everything on by defaul for these tests.
|
||||
let g:ale_completion_enabled = 1
|
||||
let g:ale_echo_cursor = 1
|
||||
let g:ale_enabled = 1
|
||||
let g:ale_fix_on_save = 1
|
||||
let g:ale_lint_on_enter = 1
|
||||
let g:ale_lint_on_filetype_changed = 1
|
||||
let g:ale_lint_on_insert_leave = 1
|
||||
let g:ale_lint_on_save = 1
|
||||
let g:ale_lint_on_text_changed = 1
|
||||
let g:ale_pattern_options_enabled = 1
|
||||
|
||||
After:
|
||||
delfunction CheckAutocmd
|
||||
@ -61,98 +74,95 @@ After:
|
||||
|
||||
call ale#events#Init()
|
||||
|
||||
Execute (g:ale_lint_on_text_changed = 0 should bind no events):
|
||||
let g:ale_lint_on_text_changed = 0
|
||||
Execute (All events should be set up when everything is on):
|
||||
let g:ale_echo_cursor = 1
|
||||
|
||||
AssertEqual [], CheckAutocmd('ALERunOnTextChangedGroup')
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 'BufEnter * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufEnter call ale#events#EnterEvent(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost call ale#Queue(0, ''lint_file'', str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufWinEnter * call ale#Queue(0, ''lint_file'', str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
|
||||
\ 'CursorHold * call ale#cursor#EchoCursorWarningWithDelay()',
|
||||
\ 'CursorMoved * call ale#cursor#EchoCursorWarningWithDelay()',
|
||||
\ 'FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand(''<abuf>'')))',
|
||||
\ 'FileType * call ale#events#FileTypeEvent( str2nr(expand(''<abuf>'')), expand(''<amatch>''))',
|
||||
\ 'InsertLeave * call ale#Queue(0)',
|
||||
\ 'InsertLeave call ale#cursor#EchoCursorWarning()',
|
||||
\ 'TextChanged * call ale#Queue(g:ale_lint_delay)',
|
||||
\ 'TextChangedI * call ale#Queue(g:ale_lint_delay)',
|
||||
\ ],
|
||||
\ CheckAutocmd('ALEEvents')
|
||||
|
||||
Execute (Only the required events should be bound even if various settings are off):
|
||||
let g:ale_completion_enabled = 0
|
||||
let g:ale_echo_cursor = 0
|
||||
let g:ale_enabled = 0
|
||||
let g:ale_fix_on_save = 0
|
||||
let g:ale_lint_on_enter = 0
|
||||
let g:ale_lint_on_filetype_changed = 0
|
||||
let g:ale_lint_on_insert_leave = 0
|
||||
let g:ale_lint_on_save = 0
|
||||
let g:ale_lint_on_text_changed = 0
|
||||
let g:ale_pattern_options_enabled = 0
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 'BufEnter * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
|
||||
\ ],
|
||||
\ CheckAutocmd('ALEEvents')
|
||||
|
||||
Execute (g:ale_lint_on_text_changed = 1 bind both events):
|
||||
let g:ale_lint_on_text_changed = 1
|
||||
|
||||
AssertEqual [
|
||||
\ 'TextChanged * call ale#Queue(g:ale_lint_delay)',
|
||||
\ 'TextChangedI * call ale#Queue(g:ale_lint_delay)'
|
||||
\], CheckAutocmd('ALERunOnTextChangedGroup')
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 'TextChanged * call ale#Queue(g:ale_lint_delay)',
|
||||
\ 'TextChangedI * call ale#Queue(g:ale_lint_delay)',
|
||||
\ ],
|
||||
\ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
|
||||
|
||||
Execute (g:ale_lint_on_text_changed = 'always' should bind both events):
|
||||
let g:ale_lint_on_text_changed = 'always'
|
||||
|
||||
AssertEqual [
|
||||
\ 'TextChanged * call ale#Queue(g:ale_lint_delay)',
|
||||
\ 'TextChangedI * call ale#Queue(g:ale_lint_delay)'
|
||||
\], CheckAutocmd('ALERunOnTextChangedGroup')
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 'TextChanged * call ale#Queue(g:ale_lint_delay)',
|
||||
\ 'TextChangedI * call ale#Queue(g:ale_lint_delay)',
|
||||
\ ],
|
||||
\ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
|
||||
|
||||
Execute (g:ale_lint_on_text_changed = 'normal' should bind only TextChanged):
|
||||
let g:ale_lint_on_text_changed = 'normal'
|
||||
|
||||
AssertEqual [
|
||||
\ 'TextChanged * call ale#Queue(g:ale_lint_delay)',
|
||||
\], CheckAutocmd('ALERunOnTextChangedGroup')
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 'TextChanged * call ale#Queue(g:ale_lint_delay)',
|
||||
\ ],
|
||||
\ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
|
||||
|
||||
Execute (g:ale_lint_on_text_changed = 'insert' should bind only TextChangedI):
|
||||
let g:ale_lint_on_text_changed = 'insert'
|
||||
|
||||
AssertEqual [
|
||||
\ 'TextChangedI * call ale#Queue(g:ale_lint_delay)',
|
||||
\], CheckAutocmd('ALERunOnTextChangedGroup')
|
||||
AssertEqual
|
||||
\ [
|
||||
\ 'TextChangedI * call ale#Queue(g:ale_lint_delay)',
|
||||
\ ],
|
||||
\ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^TextChanged''')
|
||||
|
||||
Execute (g:ale_lint_on_insert_leave = 1 should bind InsertLeave):
|
||||
let g:ale_lint_on_insert_leave = 1
|
||||
|
||||
AssertEqual [
|
||||
\ 'InsertLeave * call ale#Queue(0)',
|
||||
\], CheckAutocmd('ALERunOnInsertLeave')
|
||||
|
||||
Execute (g:ale_lint_on_insert_leave = 0 should bind no events):
|
||||
let g:ale_lint_on_insert_leave = 0
|
||||
|
||||
AssertEqual [], CheckAutocmd('ALERunOnInsertLeave')
|
||||
|
||||
Execute (g:ale_pattern_options_enabled = 1 should bind BufReadPost and BufEnter):
|
||||
let g:ale_pattern_options_enabled = 1
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufEnter * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALEPatternOptionsGroup')
|
||||
|
||||
Execute (g:ale_pattern_options_enabled = 0 should still bind events):
|
||||
let g:ale_pattern_options_enabled = 0
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufEnter * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALEPatternOptionsGroup')
|
||||
|
||||
Execute (g:ale_enabled = 0 should still bind pattern events):
|
||||
let g:ale_enabled = 0
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufEnter * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost * call ale#pattern_options#SetOptions(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALEPatternOptionsGroup')
|
||||
|
||||
Execute (g:ale_lint_on_enter = 0 should bind only the BufEnter event):
|
||||
let g:ale_lint_on_enter = 0
|
||||
let g:ale_echo_cursor = 0
|
||||
|
||||
AssertEqual
|
||||
\ ['BufEnter * call ale#events#EnterEvent(str2nr(expand(''<abuf>'')))'],
|
||||
\ CheckAutocmd('ALERunOnEnterGroup')
|
||||
|
||||
Execute (g:ale_lint_on_enter = 1 should bind the required events):
|
||||
let g:ale_lint_on_enter = 1
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufEnter * call ale#events#EnterEvent(str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufReadPost * call ale#Queue(0, ''lint_file'', str2nr(expand(''<abuf>'')))',
|
||||
\ 'BufWinEnter * call ale#Queue(0, ''lint_file'', str2nr(expand(''<abuf>'')))',
|
||||
\ 'FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALERunOnEnterGroup')
|
||||
|
||||
Execute (g:ale_lint_on_filetype_changed = 0 should bind no events):
|
||||
let g:ale_lint_on_filetype_changed = 0
|
||||
|
||||
AssertEqual [], CheckAutocmd('ALERunOnFiletypeChangeGroup')
|
||||
\ [
|
||||
\ 'InsertLeave * call ale#Queue(0)',
|
||||
\ ],
|
||||
\ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''^InsertLeave''')
|
||||
|
||||
Execute (g:ale_lint_on_filetype_changed = 1 should bind the FileType event):
|
||||
let g:ale_lint_on_filetype_changed = 1
|
||||
@ -164,30 +174,7 @@ Execute (g:ale_lint_on_filetype_changed = 1 should bind the FileType event):
|
||||
\ . 'expand(''<amatch>'')'
|
||||
\ . ')',
|
||||
\ ],
|
||||
\ CheckAutocmd('ALERunOnFiletypeChangeGroup')
|
||||
|
||||
Execute (The SaveEvent should always be bound):
|
||||
let g:ale_enabled = 0
|
||||
let g:ale_lint_on_save = 0
|
||||
let g:ale_fix_on_save = 0
|
||||
|
||||
AssertEqual [
|
||||
\ 'BufWritePost * call ale#events#SaveEvent(str2nr(expand(''<abuf>'')))',
|
||||
\], CheckAutocmd('ALERunOnSaveGroup')
|
||||
|
||||
Execute (g:ale_echo_cursor = 0 should bind no events):
|
||||
let g:ale_echo_cursor = 0
|
||||
|
||||
AssertEqual [], CheckAutocmd('ALECursorGroup')
|
||||
|
||||
Execute (g:ale_echo_cursor = 1 should bind cursor events):
|
||||
let g:ale_echo_cursor = 1
|
||||
|
||||
AssertEqual [
|
||||
\ 'CursorHold * call ale#cursor#EchoCursorWarningWithDelay()',
|
||||
\ 'CursorMoved * call ale#cursor#EchoCursorWarningWithDelay()',
|
||||
\ 'InsertLeave * call ale#cursor#EchoCursorWarning()',
|
||||
\], CheckAutocmd('ALECursorGroup')
|
||||
\ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''\v^FileType''')
|
||||
|
||||
Execute (ALECleanupGroup should include the right commands):
|
||||
AssertEqual [
|
||||
|
Loading…
Reference in New Issue
Block a user