mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-10 21:42:31 +08:00
#653 - Always set loclist or quickfix in a timer callback, which prevents errors E924, E925, and E926
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user