Add option to open loclist/quicklist when there are errors (#266)

* Add option to open loclist/quicklist when there are errors

I copied PR #137, and tries to complete it by correcting some issues and
adding vader tests.

About tests, first time with vader, can you give some feedback if there
are what you expected in PR #137.

* Remove old code + fix indent issue

* add g:ale_keep_list_window_open option

* Correct bug with keep open option

* Add comment into vader file

* Fix errors for Travis CI build
This commit is contained in:
yfery 2017-01-22 13:57:05 +01:00 committed by w0rp
parent 9820899b9e
commit a23173eeb2
4 changed files with 156 additions and 3 deletions

View File

@ -161,8 +161,8 @@ function! s:HandleExit(job) abort
let g:ale_buffer_info[l:buffer].loclist = g:ale_buffer_info[l:buffer].new_loclist
let g:ale_buffer_info[l:buffer].new_loclist = []
if g:ale_set_loclist
call setloclist(0, g:ale_buffer_info[l:buffer].loclist)
if g:ale_set_quickfix || g:ale_set_loclist
call ale#list#SetLists(g:ale_buffer_info[l:buffer].loclist)
endif
if g:ale_set_signs

49
autoload/ale/list.vim Normal file
View File

@ -0,0 +1,49 @@
" Author: Bjorn Neergaard <bjorn@neersighted.com>, modified by Yann fery <yann@fery.me>
" Description: Manages the loclist and quickfix lists
" 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('$'))
if getbufvar(l:buf, '&buftype') ==# 'quickfix'
return 1
endif
endfor
return 0
endfunction
function! ale#list#SetLists(loclist) abort
if g:ale_set_quickfix
call setqflist(a:loclist)
elseif g:ale_set_loclist
call setloclist(0, a:loclist)
endif
" If we don't auto-open lists, bail out here.
if !g:ale_open_list && !g:ale_keep_list_window_open
return
endif
" If we have errors in our list, open the list. Only if it isn't already open
if len(a:loclist) > 0 || g:ale_keep_list_window_open
let l:winnr = winnr()
if g:ale_set_quickfix
copen
elseif g:ale_set_loclist
lopen
endif
" If focus changed, restore it (jump to the last window).
if l:winnr !=# winnr()
wincmd p
endif
" Only close if the list is totally empty (relying on Vim's state, not our
" own). This keeps us from closing the window when other plugins have
" populated it.
elseif !g:ale_keep_list_window_open && g:ale_set_quickfix && len(getqflist()) == 0
cclose
elseif !g:ale_keep_list_window_open && len(getloclist(0)) == 0
lclose
endif
endfunction

View File

@ -74,8 +74,16 @@ if g:ale_lint_on_save
augroup END
endif
" This flag can be set to 0 to disable setting the loclist.
" These flags dictates if ale uses the quickfix or the loclist (loclist is the
" default, quickfix overrides loclist).
let g:ale_set_loclist = get(g:, 'ale_set_loclist', 1)
let g:ale_set_quickfix = get(g:, 'ale_set_quickfix', 0)
" This flag dictates if ale open the configured loclist
let g:ale_open_list = get(g:, 'ale_open_list', 0)
" This flag dictates if ale keeps open loclist even if there is no error in loclist
let g:ale_keep_list_window_open = get(g:, 'ale_keep_list_window_open', 0)
" This flag can be set to 0 to disable setting signs.
" This is enabled by default only if the 'signs' feature exists.

View File

@ -0,0 +1,96 @@
" Author: Yann Fery <yann@fery.me>
Before:
let g:loclist = [
\ {'lnum': 5, 'col': 5},
\ {'lnum': 5, 'col': 4},
\ {'lnum': 2, 'col': 10},
\ {'lnum': 3, 'col': 2},
\]
let g:empty_loclist = []
After:
" Close quickfix window after every execute block
lcl
ccl
unlet g:loclist
unlet g:empty_loclist
Execute (IsQuickfixOpen):
AssertEqual 0, ale#list#IsQuickfixOpen()
call setloclist(0, g:loclist)
lopen
AssertEqual 1, ale#list#IsQuickfixOpen()
lcl
AssertEqual 0, ale#list#IsQuickfixOpen()
call setqflist(g:loclist)
copen
AssertEqual 1, ale#list#IsQuickfixOpen()
ccl
AssertEqual 0, ale#list#IsQuickfixOpen()
Execute (loclist and openlist):
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_open_list = 1
let g:ale_keep_list_window_open = 0
" With empty loclist, window must stay close
call ale#list#SetLists(g:empty_loclist)
AssertEqual 0, ale#list#IsQuickfixOpen()
" With a loclist it must open
call ale#list#SetLists(g:loclist)
AssertEqual 1, ale#list#IsQuickfixOpen()
" And with keep open option, must stay open even with empty loclist
let g:ale_keep_list_window_open = 1
call ale#list#SetLists(g:empty_loclist)
AssertEqual 1, ale#list#IsQuickfixOpen()
Execute (loclist without openlist):
let g:ale_set_loclist = 1
let g:ale_set_quickfix = 0
let g:ale_open_list = 0
" Must stay close without loclist
let g:ale_keep_list_window_open = 0
call ale#list#SetLists(g:empty_loclist)
AssertEqual 0, ale#list#IsQuickfixOpen()
call ale#list#SetLists(g:loclist)
AssertEqual 0, ale#list#IsQuickfixOpen()
" Must stay open event without loclist
let g:ale_keep_list_window_open = 1
call ale#list#SetLists(g:empty_loclist)
AssertEqual 1, ale#list#IsQuickfixOpen()
call ale#list#SetLists(g:loclist)
AssertEqual 1, ale#list#IsQuickfixOpen()
Execute (quickfix and openlist):
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1
let g:ale_open_list = 1
let g:ale_keep_list_window_open = 0
" With empty loclist, window must stay close
call ale#list#SetLists(g:empty_loclist)
AssertEqual 0, ale#list#IsQuickfixOpen()
" With a loclist it must open
call ale#list#SetLists(g:loclist)
AssertEqual 1, ale#list#IsQuickfixOpen()
" And with keep open option, must stay open even with empty loclist
let g:ale_keep_list_window_open = 1
call ale#list#SetLists(g:empty_loclist)
AssertEqual 1, ale#list#IsQuickfixOpen()
Execute (quickfix without openlist):
let g:ale_set_loclist = 0
let g:ale_set_quickfix = 1
let g:ale_open_list = 0
" Must stay close without loclist
let g:ale_keep_list_window_open = 0
call ale#list#SetLists(g:empty_loclist)
AssertEqual 0, ale#list#IsQuickfixOpen()
call ale#list#SetLists(g:loclist)
AssertEqual 0, ale#list#IsQuickfixOpen()
" Must stay open event without loclist
let g:ale_keep_list_window_open = 1
call ale#list#SetLists(g:empty_loclist)
AssertEqual 1, ale#list#IsQuickfixOpen()
call ale#list#SetLists(g:loclist)
AssertEqual 1, ale#list#IsQuickfixOpen()