#653 Collect items for quickfix from all buffers, and de-duplicate them. Set filename items in quickfix and loclist.

This commit is contained in:
w0rp
2017-08-19 14:28:51 +01:00
parent 9c6e25d8d8
commit 5c839c4825
7 changed files with 180 additions and 42 deletions

View File

@@ -20,14 +20,67 @@ function! s:ShouldOpen(buffer) abort
return l:val is 1 || (l:val is# 'on_save' && l:saved)
endfunction
" A comparison function for de-duplicating loclist items for quickfix.
function! ale#list#TextLocItemCompare(left, right) abort
let l:cmp_val = ale#util#LocItemCompare(a:left, a:right)
if l:cmp_val
return l:cmp_val
endif
if a:left.text < a:right.text
return -1
endif
if a:left.text > a:right.text
return 1
endif
return 0
endfunction
function! ale#list#GetCombinedList() abort
let l:list = []
for l:info in values(g:ale_buffer_info)
call extend(l:list, l:info.loclist)
endfor
call sort(l:list, function('ale#list#TextLocItemCompare'))
call uniq(l:list, function('ale#list#TextLocItemCompare'))
return l:list
endfunction
function! s:FixList(list) abort
let l:new_list = []
for l:item in a:list
if l:item.bufnr == -1
" If the buffer number is invalid, remove it.
let l:fixed_item = copy(l:item)
call remove(l:fixed_item, 'bufnr')
else
" Don't copy the Dictionary if we do not need to.
let l:fixed_item = l:item
endif
call add(l:new_list, l:fixed_item)
endfor
return l:new_list
endfunction
function! ale#list#SetLists(buffer, loclist) abort
let l:title = expand('#' . a:buffer . ':p')
if g:ale_set_quickfix
let l:quickfix_list = ale#list#GetCombinedList()
if has('nvim')
call setqflist(a:loclist, ' ', l:title)
call setqflist(s:FixList(l:quickfix_list), ' ', l:title)
else
call setqflist(a:loclist)
call setqflist(s:FixList(l:quickfix_list))
call setqflist([], 'r', {'title': l:title})
endif
elseif g:ale_set_loclist
@@ -37,9 +90,9 @@ function! ale#list#SetLists(buffer, loclist) abort
let l:win_id = exists('*bufwinid') ? bufwinid(str2nr(a:buffer)) : 0
if has('nvim')
call setloclist(l:win_id, a:loclist, ' ', l:title)
call setloclist(l:win_id, s:FixList(a:loclist), ' ', l:title)
else
call setloclist(l:win_id, a:loclist)
call setloclist(l:win_id, s:FixList(a:loclist))
call setloclist(l:win_id, [], 'r', {'title': l:title})
endif
endif
@@ -47,6 +100,9 @@ function! ale#list#SetLists(buffer, loclist) abort
let l:keep_open = ale#Var(a:buffer, 'keep_list_window_open')
" Open a window to show the problems if we need to.
"
" We'll check if the current buffer's List is not empty here, so the
" window will only be opened if the current buffer has problems.
if s:ShouldOpen(a:buffer) && (l:keep_open || !empty(a:loclist))
let l:winnr = winnr()
let l:mode = mode()

View File

@@ -30,6 +30,16 @@ function! ale#util#LocItemCompare(left, right) abort
return 1
endif
if a:left.bufnr == -1
if a:left.filename < a:right.filename
return -1
endif
if a:left.filename > a:right.filename
return 1
endif
endif
if a:left.lnum < a:right.lnum
return -1
endif