From fba4cfeae91e6cdb0c1079f7a3807ac328d35087 Mon Sep 17 00:00:00 2001 From: Felipe Sere Date: Sun, 16 Sep 2018 15:57:13 +0100 Subject: To avoid blocking build tools, suspend ALE when suspending vim --- autoload/ale/engine.vim | 16 ++++++++++++++++ autoload/ale/toggle.vim | 19 ++----------------- plugin/ale.vim | 5 +++++ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index b6c2d3c9..05db0e49 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -18,6 +18,22 @@ if !has_key(s:, 'executable_cache_map') let s:executable_cache_map = {} endif + +function! ale#engine#CleanupEveryBuffer() abort + for l:key in keys(g:ale_buffer_info) + " The key could be a filename or a buffer number, so try and + " convert it to a number. We need a number for the other + " functions. + let l:buffer = str2nr(l:key) + + if l:buffer > 0 + " Stop all jobs and clear the results for everything, and delete + " all of the data we stored for the buffer. + call ale#engine#Cleanup(l:buffer) + endif + endfor +endfunction + function! ale#engine#ResetExecutableCache() abort let s:executable_cache_map = {} endfunction diff --git a/autoload/ale/toggle.vim b/autoload/ale/toggle.vim index 1d052b4f..8e642b3f 100644 --- a/autoload/ale/toggle.vim +++ b/autoload/ale/toggle.vim @@ -15,21 +15,6 @@ function! s:DisablePostamble() abort endif endfunction -function! s:CleanupEveryBuffer() abort - for l:key in keys(g:ale_buffer_info) - " The key could be a filename or a buffer number, so try and - " convert it to a number. We need a number for the other - " functions. - let l:buffer = str2nr(l:key) - - if l:buffer > 0 - " Stop all jobs and clear the results for everything, and delete - " all of the data we stored for the buffer. - call ale#engine#Cleanup(l:buffer) - endif - endfor -endfunction - function! ale#toggle#Toggle() abort let g:ale_enabled = !get(g:, 'ale_enabled') @@ -40,7 +25,7 @@ function! ale#toggle#Toggle() abort call ale#balloon#Enable() endif else - call s:CleanupEveryBuffer() + call ale#engine#CleanupEveryBuffer() call s:DisablePostamble() if exists('*ale#balloon#Disable') @@ -64,7 +49,7 @@ function! ale#toggle#Disable() abort endfunction function! ale#toggle#Reset() abort - call s:CleanupEveryBuffer() + call ale#engine#CleanupEveryBuffer() call ale#highlight#UpdateHighlights() endfunction diff --git a/plugin/ale.vim b/plugin/ale.vim index ffb5da8a..46b3bba6 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -218,3 +218,8 @@ augroup ALECleanupGroup autocmd BufDelete * if exists('*ale#engine#Cleanup') | call ale#engine#Cleanup(str2nr(expand(''))) | endif autocmd QuitPre * call ale#events#QuitEvent(str2nr(expand(''))) augroup END + +if exists('##VimSuspend') + autocmd VimSuspend * call ale#engine#CleanupEveryBuffer() +end + -- cgit v1.2.3 From cbf0568061b5d30af3478ca5db3bb73bd97c9981 Mon Sep 17 00:00:00 2001 From: Felipe Sere Date: Mon, 17 Sep 2018 15:50:04 +0100 Subject: Join the ALECleanupGroup and ensure we don't run cleanup if ale.vim isn't loaded --- plugin/ale.vim | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/plugin/ale.vim b/plugin/ale.vim index 46b3bba6..a49ea039 100644 --- a/plugin/ale.vim +++ b/plugin/ale.vim @@ -217,9 +217,8 @@ augroup ALECleanupGroup " Clean up buffers automatically when they are unloaded. autocmd BufDelete * if exists('*ale#engine#Cleanup') | call ale#engine#Cleanup(str2nr(expand(''))) | endif autocmd QuitPre * call ale#events#QuitEvent(str2nr(expand(''))) -augroup END - -if exists('##VimSuspend') - autocmd VimSuspend * call ale#engine#CleanupEveryBuffer() -end + if exists('##VimSuspend') + autocmd VimSuspend * if exists('*ale#engine#CleanupEveryBuffer') | call ale#engine#CleanupEveryBuffer() | endif + endif +augroup END -- cgit v1.2.3 From f09e6d638fc012b3bdccccdc3496e135fbd7df87 Mon Sep 17 00:00:00 2001 From: Felipe Sere Date: Mon, 17 Sep 2018 21:26:25 +0100 Subject: Test that we CleanupEveryBuffer when vim supports it --- test/test_autocmd_commands.vader | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/test/test_autocmd_commands.vader b/test/test_autocmd_commands.vader index 8d5048f0..4bb894ba 100644 --- a/test/test_autocmd_commands.vader +++ b/test/test_autocmd_commands.vader @@ -175,10 +175,19 @@ Execute (g:ale_lint_on_filetype_changed = 1 should bind the FileType event): \ filter(CheckAutocmd('ALEEvents'), 'v:val =~ ''\v^FileType''') Execute (ALECleanupGroup should include the right commands): - AssertEqual [ - \ 'BufDelete * if exists(''*ale#engine#Cleanup'') | call ale#engine#Cleanup(str2nr(expand(''''))) | endif', - \ 'QuitPre * call ale#events#QuitEvent(str2nr(expand('''')))', - \], CheckAutocmd('ALECleanupGroup') + if exists('##VimSuspend') + AssertEqual [ + \ 'BufDelete * if exists(''*ale#engine#Cleanup'') | call ale#engine#Cleanup(str2nr(expand(''''))) | endif', + \ 'QuitPre * call ale#events#QuitEvent(str2nr(expand('''')))', + \ 'VimSuspend * if exists(''*ale#engine#CleanupEveryBuffer'') | call ale#engine#CleanupEveryBuffer() | endif', + \], CheckAutocmd('ALECleanupGroup') + else + AssertEqual [ + \ 'BufDelete * if exists(''*ale#engine#Cleanup'') | call ale#engine#Cleanup(str2nr(expand(''''))) | endif', + \ 'QuitPre * call ale#events#QuitEvent(str2nr(expand('''')))', + \], CheckAutocmd('ALECleanupGroup') + endif + Execute(Enabling completion should set up autocmd events correctly): let g:ale_completion_enabled = 0 -- cgit v1.2.3