diff options
author | w0rp <devw0rp@gmail.com> | 2017-08-22 21:19:36 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-08-22 21:19:36 +0100 |
commit | 1a524ca63e51092ab10febea40a6f018b6e85173 (patch) | |
tree | 3d12ec01af3bfebd1bb59b7e6727f750f5641d8e /autoload | |
parent | 47a8ebc8b9ae76ee2b23e388d30324b97e102eed (diff) | |
download | ale-1a524ca63e51092ab10febea40a6f018b6e85173.zip |
#653 - Always set loclist or quickfix in a timer callback, which prevents errors E924, E925, and E926
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/engine.vim | 2 | ||||
-rw-r--r-- | autoload/ale/events.vim | 52 | ||||
-rw-r--r-- | autoload/ale/list.vim | 32 | ||||
-rw-r--r-- | autoload/ale/util.vim | 30 |
4 files changed, 61 insertions, 55 deletions
diff --git a/autoload/ale/engine.vim b/autoload/ale/engine.vim index 40930038..2875d4ad 100644 --- a/autoload/ale/engine.vim +++ b/autoload/ale/engine.vim @@ -708,7 +708,7 @@ function! s:RemoveProblemsForDisabledLinters(buffer, linters) abort call filter( \ get(g:ale_buffer_info[a:buffer], 'loclist', []), - \ 'get(l:name_map, v:val.linter_name)', + \ 'get(l:name_map, get(v:val, ''linter_name''))', \) endfunction diff --git a/autoload/ale/events.vim b/autoload/ale/events.vim index 2ee7f86a..a3b74677 100644 --- a/autoload/ale/events.vim +++ b/autoload/ale/events.vim @@ -45,55 +45,3 @@ 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("\<CR>", 'n') - - " If we hit one of the errors and cleared it, then Vim didn't - " move to the position we wanted. Change the position to the one - " the user selected. - if exists('g:ale_list_window_selection') - let l:pos = getcurpos() - let [l:pos[1], l:pos[2]] = g:ale_list_window_selection - call setpos('.', l:pos) - endif - endif - endif - - " Always clear the last selection when trying to cancel the errors above - " here. This prevents us from remembering invalid positions. - unlet! g:ale_list_window_selection -endfunction - -function! ale#events#BufWinLeave() abort - call timer_start(0, function('s:HitReturn')) -endfunction - -" Grab the position for a problem from the loclist or quickfix windows -" when moving through selections. This selection will be remembered and -" set as the position when jumping to an error in another file. -function! ale#events#ParseLoclistWindowItemPosition() abort - " Parses lines like - " test.txt|72 col 5 error| ... - " test.txt|72| ... - let l:match = matchlist(getline('.'), '\v^[^|]+\|(\d+)( [^ ]+ )?(\d*)') - - if !empty(l:match) - let g:ale_list_window_selection = [ - \ l:match[1] + 0, - \ max([l:match[3] + 0, 1]), - \] - endif -endfunction diff --git a/autoload/ale/list.vim b/autoload/ale/list.vim index 25920ce6..7b2bf2cb 100644 --- a/autoload/ale/list.vim +++ b/autoload/ale/list.vim @@ -1,6 +1,10 @@ " Author: Bjorn Neergaard <bjorn@neersighted.com>, modified by Yann fery <yann@fery.me> " Description: Manages the loclist and quickfix lists +if !exists('s:timer_args') + let s:timer_args = {} +endif + " Return 1 if there is a buffer with buftype == 'quickfix' in bufffer list function! ale#list#IsQuickfixOpen() abort for l:buf in range(1, bufnr('$')) @@ -52,7 +56,7 @@ function! s:FixList(list) abort return l:new_list endfunction -function! ale#list#SetLists(buffer, loclist) abort +function! s:SetListsImpl(timer_id, buffer, loclist) abort let l:title = expand('#' . a:buffer . ':p') if g:ale_set_quickfix @@ -115,7 +119,19 @@ function! ale#list#SetLists(buffer, loclist) abort endif endfunction -function! ale#list#CloseWindowIfNeeded(buffer) abort +function! ale#list#SetLists(buffer, loclist) abort + if get(g:, 'ale_set_lists_synchronously') == 1 + call s:SetListsImpl(-1, a:buffer, a:loclist) + else + call ale#util#StartPartialTimer( + \ 0, + \ function('s:SetListsImpl'), + \ [a:buffer, a:loclist], + \) + endif +endfunction + +function! s:CloseWindowIfNeededImpl(timer_id, buffer) abort if ale#Var(a:buffer, 'keep_list_window_open') || !s:ShouldOpen(a:buffer) return endif @@ -134,3 +150,15 @@ function! ale#list#CloseWindowIfNeeded(buffer) abort catch /E444/ endtry endfunction + +function! ale#list#CloseWindowIfNeeded(buffer) abort + if get(g:, 'ale_set_lists_synchronously') == 1 + call s:CloseWindowIfNeededImpl(-1, a:buffer) + else + call ale#util#StartPartialTimer( + \ 0, + \ function('s:CloseWindowIfNeededImpl'), + \ [a:buffer], + \) + endif +endfunction diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index c46579b0..cf8d5bec 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -267,3 +267,33 @@ function! ale#util#Writefile(buffer, lines, filename) abort call writefile(l:corrected_lines, a:filename) " no-custom-checks endfunction + +if !exists('s:patial_timers') + let s:partial_timers = {} +endif + +function! s:ApplyPartialTimer(timer_id) abort + let [l:Callback, l:args] = remove(s:partial_timers, a:timer_id) + call call(l:Callback, [a:timer_id] + l:args) +endfunction + +" Given a delay, a callback, a List of arguments, start a timer with +" timer_start() and call the callback provided with [timer_id] + args. +" +" The timer must not be stopped with timer_stop(). +" Use ale#util#StopPartialTimer() instead, which can stop any timer, and will +" clear any arguments saved for executing callbacks later. +function! ale#util#StartPartialTimer(delay, callback, args) abort + let l:timer_id = timer_start(a:delay, function('s:ApplyPartialTimer')) + let s:partial_timers[l:timer_id] = [a:callback, a:args] + + return l:timer_id +endfunction + +function! ale#util#StopPartialTimer(timer_id) abort + call timer_stop(a:timer_id) + + if has_key(s:partial_timers, a:timer_id) + call remove(s:partial_timers, a:timer_id) + endif +endfunction |