#376 Use the window ID for a given buffer for setting the loclist

This commit is contained in:
w0rp 2017-03-09 00:43:53 +00:00
parent 1c3f0b1e19
commit ad49846a48
5 changed files with 29 additions and 14 deletions

View File

@ -255,7 +255,7 @@ endfunction
function! ale#engine#SetResults(buffer, loclist) abort
if g:ale_set_quickfix || g:ale_set_loclist
call ale#list#SetLists(a:loclist)
call ale#list#SetLists(a:buffer, a:loclist)
endif
if g:ale_set_signs

View File

@ -11,11 +11,11 @@ function! ale#list#IsQuickfixOpen() abort
return 0
endfunction
function! ale#list#SetLists(loclist) abort
function! ale#list#SetLists(buffer, loclist) abort
if g:ale_set_quickfix
call setqflist(a:loclist)
elseif g:ale_set_loclist
call setloclist(0, a:loclist)
call setloclist(bufwinid(str2nr(a:buffer)), a:loclist)
endif
" If we don't auto-open lists, bail out here.

View File

@ -194,7 +194,9 @@ function! s:ALEToggle() abort
" Lint immediately
call ale#Queue(0)
else
for l:buffer in keys(g:ale_buffer_info)
" Make sure the buffer number is a number, not a string,
" otherwise things can go wrong.
for l:buffer in map(keys(g:ale_buffer_info), 'str2nr(v:val)')
" Stop jobs and delete stored buffer data
call ale#cleanup#Buffer(l:buffer)
" Clear signs, loclist, quicklist

View File

@ -35,18 +35,18 @@ Execute(IsQuickfixOpen should return the right output):
AssertEqual 0, ale#list#IsQuickfixOpen()
Execute(The quickfix window should not open by default for the loclist):
call ale#list#SetLists(g:loclist)
call ale#list#SetLists(bufnr('%'), g:loclist)
Assert !ale#list#IsQuickfixOpen()
Execute(The quickfix window should open for just the loclist):
let g:ale_open_list = 1
" It should not open for an empty list.
call ale#list#SetLists([])
call ale#list#SetLists(bufnr('%'), [])
Assert !ale#list#IsQuickfixOpen()
" With a non-empty loclist, the window must open.
call ale#list#SetLists(g:loclist)
call ale#list#SetLists(bufnr('%'), g:loclist)
Assert ale#list#IsQuickfixOpen()
Execute(The quickfix window should stay open for just the loclist):
@ -54,14 +54,14 @@ Execute(The quickfix window should stay open for just the loclist):
let g:ale_keep_list_window_open = 1
" The window should stay open after even after it is made blank again.
call ale#list#SetLists(g:loclist)
call ale#list#SetLists([])
call ale#list#SetLists(bufnr('%'), g:loclist)
call ale#list#SetLists(bufnr('%'), [])
Assert ale#list#IsQuickfixOpen()
Execute(The quickfix window should not open by default when quickfix is on):
let g:ale_set_quickfix = 1
call ale#list#SetLists(g:loclist)
call ale#list#SetLists(bufnr('%'), g:loclist)
Assert !ale#list#IsQuickfixOpen()
Execute(The quickfix window should open for the quickfix list):
@ -69,11 +69,11 @@ Execute(The quickfix window should open for the quickfix list):
let g:ale_open_list = 1
" It should not open for an empty list.
call ale#list#SetLists([])
call ale#list#SetLists(bufnr('%'), [])
Assert !ale#list#IsQuickfixOpen()
" With a non-empty quickfix list, the window must open.
call ale#list#SetLists(g:loclist)
call ale#list#SetLists(bufnr('%'), g:loclist)
Assert ale#list#IsQuickfixOpen()
Execute(The quickfix window should stay open for the quickfix list):
@ -82,6 +82,6 @@ Execute(The quickfix window should stay open for the quickfix list):
let g:ale_keep_list_window_open = 1
" The window should stay open after even after it is made blank again.
call ale#list#SetLists(g:loclist)
call ale#list#SetLists([])
call ale#list#SetLists(bufnr('%'), g:loclist)
call ale#list#SetLists(bufnr('%'), [])
Assert ale#list#IsQuickfixOpen()

View File

@ -0,0 +1,13 @@
Before:
let g:original_buffer = bufnr('%')
new
After:
unlet! g:original_buffer
Execute(Errors should be set in the loclist for the original buffer, not the new one):
call ale#list#SetLists(g:original_buffer, [{'lnum': 4, 'text': 'foo'}])
AssertEqual [], getloclist(0)
AssertEqual 1, len(getloclist(bufwinid(g:original_buffer)))
AssertEqual 'foo', getloclist(bufwinid(g:original_buffer))[0].text