diff --git a/autoload/ale/completion.vim b/autoload/ale/completion.vim index 44d4e0e..9f4e3c2 100644 --- a/autoload/ale/completion.vim +++ b/autoload/ale/completion.vim @@ -1,10 +1,6 @@ " Author: w0rp " Description: Completion support for LSP linters -" A do-nothing function so we can load this autoload file in tests. -function! ale#completion#Nop() abort -endfunction - let s:timer_id = -1 function! s:GetRegex(map, filetype) abort @@ -110,11 +106,6 @@ function! ale#completion#OmniFunc(findstart, base) abort endif endfunction -" A wrapper function for feedkeys so we can test calls for it. -function! ale#completion#FeedKeys(string, mode) abort - call feedkeys(a:string, a:mode) -endfunction - function! ale#completion#Show(response, completion_parser) abort " Remember the old omnifunc value, if there is one. " If we don't store an old one, we'll just never reset the option. @@ -129,7 +120,7 @@ function! ale#completion#Show(response, completion_parser) abort let b:ale_completion_parser = a:completion_parser let &l:omnifunc = 'ale#completion#OmniFunc' call s:ReplaceCompleteopt() - call ale#completion#FeedKeys("\\", 'n') + call ale#util#FeedKeys("\\", 'n') endfunction function! s:CompletionStillValid(request_id) abort diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim index a3b7467..c84954c 100644 --- a/autoload/ale/events.vim +++ b/autoload/ale/events.vim @@ -45,3 +45,25 @@ function! ale#events#FileChangedEvent(buffer) abort call s:LintOnEnter(a:buffer) endif endfunction + +" When changing quickfix or a loclist window while the window is open +" from autocmd events and while navigating from one buffer to another, Vim +" will complain saying that the window has closed or that the lists have +" changed. +" +" This timer callback just accepts those errors when they appear. +function! s:HitReturn(...) abort + if ale#util#Mode() is# 'r' + redir => l:output + silent mess + redir end + + if get(split(l:output, "\n"), -1, '') =~# '^E92[456]' + call ale#util#FeedKeys("\", 'n') + endif + endif +endfunction + +function! ale#events#BufWinLeave() abort + call timer_start(0, function('s:HitReturn')) +endfunction diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index fd53842..c46579b 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -1,11 +1,23 @@ " Author: w0rp " Description: Contains miscellaneous functions -" A null file for sending output to nothing. -let g:ale#util#nul_file = '/dev/null' +" A wrapper function for mode() so we can test calls for it. +function! ale#util#Mode(...) abort + return call('mode', a:000) +endfunction -if has('win32') - let g:ale#util#nul_file = 'nul' +" A wrapper function for feedkeys so we can test calls for it. +function! ale#util#FeedKeys(...) abort + return call('feedkeys', a:000) +endfunction + +if !exists('g:ale#util#nul_file') + " A null file for sending output to nothing. + let g:ale#util#nul_file = '/dev/null' + + if has('win32') + let g:ale#util#nul_file = 'nul' + endif endif " Return the number of lines for a given buffer. diff --git a/plugin/ale.vim b/plugin/ale.vim index a9ab88a..d33f3c5 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -226,6 +226,7 @@ function! ALEInitAuGroups() abort autocmd BufWinEnter,BufRead * call ale#Queue(0, 'lint_file', str2nr(expand(''))) " Track when the file is changed outside of Vim. autocmd FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand(''))) + autocmd BufWinLeave * call ale#events#BufWinLeave() endif augroup END diff --git a/test/test_ale_init_au_groups.vader b/test/test_ale_init_au_groups.vader index 216e7cf..109f84a 100644 --- a/test/test_ale_init_au_groups.vader +++ b/test/test_ale_init_au_groups.vader @@ -128,6 +128,7 @@ Execute (g:ale_lint_on_enter = 1 should bind the required events): \ 'BufEnter * call ale#events#EnterEvent(str2nr(expand('''')))', \ 'BufReadPost * call ale#Queue(0, ''lint_file'', str2nr(expand('''')))', \ 'BufWinEnter * call ale#Queue(0, ''lint_file'', str2nr(expand('''')))', + \ 'BufWinLeave * call ale#events#BufWinLeave()', \ 'FileChangedShellPost * call ale#events#FileChangedEvent(str2nr(expand('''')))', \], CheckAutocmd('ALERunOnEnterGroup') diff --git a/test/test_completion.vader b/test/test_completion.vader index f3f552b..811a264 100644 --- a/test/test_completion.vader +++ b/test/test_completion.vader @@ -9,9 +9,7 @@ Before: \ 'feedkeys_calls': [], \} - call ale#completion#Nop() - - function! ale#completion#FeedKeys(string, mode) abort + function! ale#util#FeedKeys(string, mode) abort call add(g:test_vars.feedkeys_calls, [a:string, a:mode]) endfunction diff --git a/test/test_list_modification_error_cancelling.vader b/test/test_list_modification_error_cancelling.vader new file mode 100644 index 0000000..0644962 --- /dev/null +++ b/test/test_list_modification_error_cancelling.vader @@ -0,0 +1,54 @@ +Before: + let b:fake_mode = 'r' + let b:feedkeys_calls = [] + + " Mock mode() and feedkeys() for the check + function! ale#util#Mode(...) abort + return b:fake_mode + endfunction + + function! ale#util#FeedKeys(...) abort + call add(b:feedkeys_calls, a:000) + endfunction + + function! CheckError(mode, message, expected_list) abort + let b:fake_mode = a:mode + + echom a:message + + call ale#events#BufWinLeave() + AssertEqual [], b:feedkeys_calls + + sleep 1ms + AssertEqual a:expected_list, b:feedkeys_calls + endfunction + +After: + unlet! b:fake_mode + unlet! b:feedkeys_calls + + delfunction CheckError + + runtime autoload/ale/util.vim + +Execute(The BufWinLeave event function should hide E924 errors): + " For some reason, this test fails the first time when running in NeoVim + " in Docker, so just execute this twice. + echom 'E924' + call ale#events#BufWinLeave() + sleep 1ms + let b:feedkeys_calls = [] + + call CheckError('r', 'E924', [["\", 'n']]) + +Execute(The BufWinLeave event function should hide E925 errors): + call CheckError('r', 'E925', [["\", 'n']]) + +Execute(The BufWinLeave event function should hide E926 errors): + call CheckError('r', 'E926', [["\", 'n']]) + +Execute(The BufWinLeave event function should ignore other errors): + call CheckError('r', 'E999', []) + +Execute(The BufWinLeave event function not send keys for other modes): + call CheckError('n', 'E924', [])