diff --git a/autoload/ale.vim b/autoload/ale.vim index 62a8bf4d..4286e4af 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -6,6 +6,13 @@ let s:lint_timer = -1 let s:queued_buffer_number = -1 let s:should_lint_file_for_buffer = {} +" Return 1 if a file is too large for ALE to handle. +function! ale#FileTooLarge() abort + let l:max = ale#Var(bufnr(''), 'maximum_file_size') + + return l:max > 0 ? (line2byte(line('$') + 1) > l:max) : 0 +endfunction + " A function for checking various conditions whereby ALE just shouldn't " attempt to do anything, say if particular buffer types are open in Vim. function! ale#ShouldDoNothing() abort @@ -14,6 +21,8 @@ function! ale#ShouldDoNothing() abort return index(g:ale_filetype_blacklist, &filetype) >= 0 \ || (exists('*getcmdwintype') && !empty(getcmdwintype())) \ || ale#util#InSandbox() + \ || !ale#Var(bufnr(''), 'enabled') + \ || ale#FileTooLarge() endfunction " (delay, [linting_flag]) @@ -29,11 +38,6 @@ function! ale#Queue(delay, ...) abort throw "linting_flag must be either '' or 'lint_file'" endif - " Stop here if ALE is disabled. - if !ale#Var(bufnr(''), 'enabled') - return - endif - if ale#ShouldDoNothing() return endif diff --git a/autoload/ale/cursor.vim b/autoload/ale/cursor.vim index 572880a9..86391d5c 100644 --- a/autoload/ale/cursor.vim +++ b/autoload/ale/cursor.vim @@ -66,11 +66,6 @@ function! s:StopCursorTimer() abort endfunction function! ale#cursor#EchoCursorWarning(...) abort - " Stop here if ALE is disabled. - if !ale#Var(bufnr(''), 'enabled') - return - endif - if ale#ShouldDoNothing() return endif @@ -98,11 +93,6 @@ let s:cursor_timer = -1 let s:last_pos = [0, 0, 0] function! ale#cursor#EchoCursorWarningWithDelay() abort - " Stop here if ALE is disabled. - if !ale#Var(bufnr(''), 'enabled') - return - endif - if ale#ShouldDoNothing() return endif @@ -122,6 +112,10 @@ function! ale#cursor#EchoCursorWarningWithDelay() abort endfunction function! ale#cursor#ShowCursorDetail() abort + if ale#ShouldDoNothing() + return + endif + " Only echo the warnings in normal mode, otherwise we will get problems. if mode() !=# 'n' return diff --git a/doc/ale.txt b/doc/ale.txt index 4868e17c..5dd8d053 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -514,6 +514,15 @@ g:ale_max_buffer_history_size *g:ale_max_buffer_history_size* History can be disabled completely with |g:ale_history_enabled|. +g:ale_maximum_file_size *g:ale_maximum_file_size* + *b:ale_maximum_file_size* + Type: |Number| + Default: `0` + + A maximum file size in bytes for ALE to check. If set to any positive + number, ALE will skip checking files larger than the given size. + + g:ale_open_list *g:ale_open_list* Type: |Number| diff --git a/plugin/ale.vim b/plugin/ale.vim index 14e880d9..b5991549 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -167,6 +167,9 @@ let g:ale_history_log_output = get(g:, 'ale_history_log_output', 0) call ale#Set('pattern_options', {}) call ale#Set('pattern_options_enabled', !empty(g:ale_pattern_options)) +" A maximum file size for checking for errors. +call ale#Set('maximum_file_size', 0) + 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 diff --git a/test/test_disabling_ale.vader b/test/test_disabling_ale.vader index b08c5b1d..6159f793 100644 --- a/test/test_disabling_ale.vader +++ b/test/test_disabling_ale.vader @@ -1,5 +1,27 @@ Before: - Save g:ale_buffer_info, g:ale_enabled, b:ale_enabled + Save g:ale_buffer_info + Save g:ale_enabled + Save b:ale_enabled + Save g:ale_maximum_file_size + Save b:ale_maximum_file_size + + function! SetUpCursorData() + let g:ale_buffer_info = { + \ bufnr('%'): { + \ 'loclist': [ + \ { + \ 'lnum': 2, + \ 'col': 10, + \ 'linter_name': 'testlinter', + \ 'type': 'W', + \ 'text': 'X' + \ }, + \ ], + \ }, + \} + + call cursor(2, 16) + endfunction function! TestCallback(buffer, output) return [] @@ -29,6 +51,7 @@ After: call ale#linter#Reset() delfunction TestCallback delfunction GetLastMessage + delfunction SetUpCursorData Given foobar (Some imaginary filetype): foo @@ -43,6 +66,14 @@ Execute(Linting shouldn't happen when ALE is disabled globally): AssertEqual {}, g:ale_buffer_info +Execute(Linting shouldn't happen when the file is too large with a global options): + let g:ale_maximum_file_size = 12 + let g:ale_buffer_info = {} + + call ale#Queue(0) + + AssertEqual {}, g:ale_buffer_info + Execute(Linting shouldn't happen when ALE is disabled locally): let b:ale_enabled = 0 let g:ale_buffer_info = {} @@ -51,42 +82,38 @@ Execute(Linting shouldn't happen when ALE is disabled locally): AssertEqual {}, g:ale_buffer_info +Execute(Linting shouldn't happen when the file is too large with a local options): + let b:ale_maximum_file_size = 12 + let g:ale_buffer_info = {} + + call ale#Queue(0) + + AssertEqual {}, g:ale_buffer_info + Execute(Cursor warnings shouldn't be echoed when ALE is disabled globally): let g:ale_enabled = 0 - let g:ale_buffer_info = { - \ bufnr('%'): { - \ 'loclist': [ - \ { - \ 'lnum': 2, - \ 'col': 10, - \ 'linter_name': 'testlinter', - \ 'type': 'W', - \ 'text': 'X' - \ }, - \ ], - \ }, - \} - call cursor(2, 16) + call SetUpCursorData() + call ale#cursor#EchoCursorWarning() + AssertEqual '', GetLastMessage() + +Execute(Cursor warnings shouldn't be echoed when the file is too large with global options): + let g:ale_maximum_file_size = 12 + + call SetUpCursorData() call ale#cursor#EchoCursorWarning() AssertEqual '', GetLastMessage() Execute(Cursor warnings shouldn't be echoed when ALE is disabled locally): let b:ale_enabled = 0 - let g:ale_buffer_info = { - \ bufnr('%'): { - \ 'loclist': [ - \ { - \ 'lnum': 2, - \ 'col': 10, - \ 'linter_name': 'testlinter', - \ 'type': 'W', - \ 'text': 'X' - \ }, - \ ], - \ }, - \} - call cursor(2, 16) + call SetUpCursorData() + call ale#cursor#EchoCursorWarning() + AssertEqual '', GetLastMessage() + +Execute(Cursor warnings shouldn't be echoed when the file is too large with local options): + let b:ale_maximum_file_size = 12 + + call SetUpCursorData() call ale#cursor#EchoCursorWarning() AssertEqual '', GetLastMessage()