#1497 Tolerate important ALE variables being undefined for some reason when viewing buffers like git commits
This commit is contained in:
parent
3401a4e8ea
commit
0cd8e8630b
@ -33,6 +33,10 @@ endfunction
|
|||||||
|
|
||||||
" Return 1 if a file is too large for ALE to handle.
|
" Return 1 if a file is too large for ALE to handle.
|
||||||
function! ale#FileTooLarge() abort
|
function! ale#FileTooLarge() abort
|
||||||
|
if !exists('g:ale_maximum_file_size')
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
let l:max = ale#Var(bufnr(''), 'maximum_file_size')
|
let l:max = ale#Var(bufnr(''), 'maximum_file_size')
|
||||||
|
|
||||||
return l:max > 0 ? (line2byte(line('$') + 1) > l:max) : 0
|
return l:max > 0 ? (line2byte(line('$') + 1) > l:max) : 0
|
||||||
@ -46,13 +50,18 @@ function! ale#ShouldDoNothing(buffer) abort
|
|||||||
" The checks are split into separate if statements to make it possible to
|
" The checks are split into separate if statements to make it possible to
|
||||||
" profile each check individually with Vim's profiling tools.
|
" profile each check individually with Vim's profiling tools.
|
||||||
|
|
||||||
|
" Do nothing if ALE is disabled.
|
||||||
|
if !getbufvar(a:buffer, 'ale_enabled', get(g:, 'ale_enabled', 0))
|
||||||
|
return 1
|
||||||
|
endif
|
||||||
|
|
||||||
" Don't perform any checks when newer NeoVim versions are exiting.
|
" Don't perform any checks when newer NeoVim versions are exiting.
|
||||||
if get(v:, 'exiting', v:null) isnot v:null
|
if get(v:, 'exiting', v:null) isnot v:null
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Do nothing for blacklisted files
|
" Do nothing for blacklisted files
|
||||||
if index(g:ale_filetype_blacklist, getbufvar(a:buffer, '&filetype')) >= 0
|
if index(get(g:, 'ale_filetype_blacklist', []), getbufvar(a:buffer, '&filetype')) >= 0
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
@ -72,11 +81,6 @@ function! ale#ShouldDoNothing(buffer) abort
|
|||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Do nothing if ALE is disabled.
|
|
||||||
if !ale#Var(a:buffer, 'enabled')
|
|
||||||
return 1
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Do nothing if the file is too large.
|
" Do nothing if the file is too large.
|
||||||
if ale#FileTooLarge()
|
if ale#FileTooLarge()
|
||||||
return 1
|
return 1
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
Before:
|
Before:
|
||||||
Save g:ale_filetype_blacklist
|
runtime autoload/ale.vim
|
||||||
|
|
||||||
" Delete some variable which should be defined.
|
" Replace one of the key ALE functions and make it throw.
|
||||||
unlet! g:ale_filetype_blacklist
|
function! ale#FileTooLarge() abort
|
||||||
|
throw 'broken'
|
||||||
|
endfunction
|
||||||
|
|
||||||
After:
|
After:
|
||||||
Restore
|
runtime autoload/ale.vim
|
||||||
|
|
||||||
call ale#ResetErrorDelays()
|
call ale#ResetErrorDelays()
|
||||||
|
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
Before:
|
Before:
|
||||||
|
Save g:ale_filetype_blacklist
|
||||||
|
Save g:ale_maximum_file_size
|
||||||
|
Save g:ale_enabled
|
||||||
Save &l:statusline
|
Save &l:statusline
|
||||||
|
|
||||||
call ale#test#SetDirectory('/testplugin/test')
|
call ale#test#SetDirectory('/testplugin/test')
|
||||||
@ -12,6 +15,8 @@ Before:
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
After:
|
After:
|
||||||
|
Restore
|
||||||
|
|
||||||
call ale#test#RestoreDirectory()
|
call ale#test#RestoreDirectory()
|
||||||
|
|
||||||
if b:funky_command_created
|
if b:funky_command_created
|
||||||
@ -21,8 +26,6 @@ After:
|
|||||||
|
|
||||||
unlet! b:funky_command_created
|
unlet! b:funky_command_created
|
||||||
|
|
||||||
Restore
|
|
||||||
|
|
||||||
Execute(ALE shouldn't do much of anything for ctrlp-funky buffers):
|
Execute(ALE shouldn't do much of anything for ctrlp-funky buffers):
|
||||||
Assert !ale#ShouldDoNothing(bufnr('')), 'The preliminary check failed'
|
Assert !ale#ShouldDoNothing(bufnr('')), 'The preliminary check failed'
|
||||||
|
|
||||||
@ -39,3 +42,11 @@ Execute(ALE shouldn't try to check buffers with '.' as the filename):
|
|||||||
silent! noautocmd file .
|
silent! noautocmd file .
|
||||||
|
|
||||||
Assert ale#ShouldDoNothing(bufnr(''))
|
Assert ale#ShouldDoNothing(bufnr(''))
|
||||||
|
|
||||||
|
Execute(The DoNothing check should work if the ALE globals aren't defined):
|
||||||
|
unlet! g:ale_filetype_blacklist
|
||||||
|
unlet! g:ale_maximum_file_size
|
||||||
|
unlet! g:ale_enabled
|
||||||
|
|
||||||
|
" This shouldn't throw exceptions.
|
||||||
|
call ale#ShouldDoNothing(bufnr(''))
|
||||||
|
Loading…
Reference in New Issue
Block a user