From 18509195f575c5753d3b30ff87040674cca6ce01 Mon Sep 17 00:00:00 2001 From: w0rp Date: Mon, 28 May 2018 17:38:14 +0100 Subject: [PATCH] #1524 Do not try to check buffers with empty filetypes --- autoload/ale.vim | 16 ++++++++++++---- autoload/ale/engine.vim | 2 ++ test/sign/test_sign_placement.vader | 2 ++ test/test_alelint_autocmd.vader | 1 + test/test_engine_lsp_response_handling.vader | 1 + test/test_lint_error_delay.vader | 1 + test/test_should_do_nothing_conditions.vader | 11 +++++++++++ test/test_temporary_file_management.vader | 19 +++++++++++++++++++ test/test_verilog_verilator_options.vader | 1 - 9 files changed, 49 insertions(+), 5 deletions(-) diff --git a/autoload/ale.vim b/autoload/ale.vim index 5c4a0f5..725a395 100644 --- a/autoload/ale.vim +++ b/autoload/ale.vim @@ -60,23 +60,31 @@ function! ale#ShouldDoNothing(buffer) abort return 1 endif - " Do nothing for blacklisted files - if index(get(g:, 'ale_filetype_blacklist', []), getbufvar(a:buffer, '&filetype')) >= 0 + let l:filetype = getbufvar(a:buffer, '&filetype') + + " Do nothing when there's no filetype. + if l:filetype is# '' return 1 endif - " Do nothing if running from command mode + " Do nothing for blacklisted files. + if index(get(g:, 'ale_filetype_blacklist', []), l:filetype) >= 0 + return 1 + endif + + " Do nothing if running from command mode. if s:getcmdwintype_exists && !empty(getcmdwintype()) return 1 endif let l:filename = fnamemodify(bufname(a:buffer), ':t') + " Do nothing for directories. if l:filename is# '.' return 1 endif - " Do nothing if running in the sandbox + " Do nothing if running in the sandbox. if ale#util#InSandbox() return 1 endif diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 5cd1218..f988d1b 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -98,11 +98,13 @@ endfunction " Register a temporary file to be managed with the ALE engine for " a current job run. function! ale#engine#ManageFile(buffer, filename) abort + call ale#engine#InitBufferInfo(a:buffer) call add(g:ale_buffer_info[a:buffer].temporary_file_list, a:filename) endfunction " Same as the above, but manage an entire directory. function! ale#engine#ManageDirectory(buffer, directory) abort + call ale#engine#InitBufferInfo(a:buffer) call add(g:ale_buffer_info[a:buffer].temporary_directory_list, a:directory) endfunction diff --git a/test/sign/test_sign_placement.vader b/test/sign/test_sign_placement.vader index 36f34e1..19267fe 100644 --- a/test/sign/test_sign_placement.vader +++ b/test/sign/test_sign_placement.vader @@ -1,7 +1,9 @@ Before: Save g:ale_set_signs + Save g:ale_buffer_info let g:ale_set_signs = 1 + let g:ale_buffer_info = {} call ale#linter#Reset() sign unplace * diff --git a/test/test_alelint_autocmd.vader b/test/test_alelint_autocmd.vader index d51694f..5af1cd4 100644 --- a/test/test_alelint_autocmd.vader +++ b/test/test_alelint_autocmd.vader @@ -14,6 +14,7 @@ After: catch endtry +Given foobar(An empty file): Execute(Run a lint cycle, and check that a variable is set in the autocmd): augroup VaderTest autocmd! diff --git a/test/test_engine_lsp_response_handling.vader b/test/test_engine_lsp_response_handling.vader index 4c6fe63..3d317e9 100644 --- a/test/test_engine_lsp_response_handling.vader +++ b/test/test_engine_lsp_response_handling.vader @@ -13,6 +13,7 @@ After: call ale#linter#Reset() call ale#engine#ClearLSPData() +Given foobar(An empty file): Execute(tsserver syntax error responses should be handled correctly): runtime ale_linters/typescript/tsserver.vim call ale#test#SetFilename('filename.ts') diff --git a/test/test_lint_error_delay.vader b/test/test_lint_error_delay.vader index 0566489..d539708 100644 --- a/test/test_lint_error_delay.vader +++ b/test/test_lint_error_delay.vader @@ -11,6 +11,7 @@ After: call ale#ResetErrorDelays() +Given foobar(An empty file): Execute(ALE should stop queuing for a while after exceptions are thrown): AssertThrows call ale#Queue(100) call ale#Queue(100) diff --git a/test/test_should_do_nothing_conditions.vader b/test/test_should_do_nothing_conditions.vader index 85874e5..062ab87 100644 --- a/test/test_should_do_nothing_conditions.vader +++ b/test/test_should_do_nothing_conditions.vader @@ -26,6 +26,7 @@ After: unlet! b:funky_command_created +Given foobar(An empty file): Execute(ALE shouldn't do much of anything for ctrlp-funky buffers): Assert !ale#ShouldDoNothing(bufnr('')), 'The preliminary check failed' @@ -43,6 +44,16 @@ Execute(ALE shouldn't try to check buffers with '.' as the filename): Assert ale#ShouldDoNothing(bufnr('')) +Execute(DoNothing should return 0 when the filetype is empty): + AssertEqual + \ 0, + \ ale#ShouldDoNothing(bufnr('')), + \ 'ShouldDoNothing() was 1 for some other reason' + + set filetype= + + AssertEqual 1, 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 diff --git a/test/test_temporary_file_management.vader b/test/test_temporary_file_management.vader index ae2bf25..e248331 100644 --- a/test/test_temporary_file_management.vader +++ b/test/test_temporary_file_management.vader @@ -1,4 +1,7 @@ Before: + Save g:ale_buffer_info + + let g:ale_buffer_info = {} let g:ale_run_synchronously = 1 let g:command = 'echo test' @@ -41,6 +44,8 @@ Before: \}) After: + Restore + if !empty(g:preserved_directory) call delete(g:preserved_directory, 'rf') endif @@ -111,3 +116,17 @@ Execute(ALE should create and delete directories for ale#engine#CreateDirectory( Assert !isdirectory(b:dir), 'The directory was not deleted' Assert !isdirectory(b:dir2), 'The second directory was not deleted' + +Execute(ale#engine#ManageFile should add the file even if the buffer info hasn't be set yet): + let g:ale_buffer_info = {} + call ale#engine#ManageFile(bufnr(''), '/foo/bar') + AssertEqual + \ ['/foo/bar'], + \ g:ale_buffer_info[bufnr('')].temporary_file_list + +Execute(ale#engine#ManageDirectory should add the directory even if the buffer info hasn't be set yet): + let g:ale_buffer_info = {} + call ale#engine#ManageDirectory(bufnr(''), '/foo/bar') + AssertEqual + \ ['/foo/bar'], + \ g:ale_buffer_info[bufnr('')].temporary_directory_list diff --git a/test/test_verilog_verilator_options.vader b/test/test_verilog_verilator_options.vader index 561786e..e53037b 100644 --- a/test/test_verilog_verilator_options.vader +++ b/test/test_verilog_verilator_options.vader @@ -22,4 +22,3 @@ Execute(Set Verilog Verilator linter additional options to `-sv --default-langua \ g:matched , \ -1 , \ 'Additionnal arguments not found in the run command' -