diff options
author | w0rp <devw0rp@gmail.com> | 2017-08-19 14:28:51 +0100 |
---|---|---|
committer | w0rp <devw0rp@gmail.com> | 2017-08-19 14:28:51 +0100 |
commit | 5c839c482573263b4d3cb2bc4bc1719d49e14e22 (patch) | |
tree | 8d4bdea46296f79dacd035becd13167e89c1b112 /autoload | |
parent | 9c6e25d8d8a8d519e828c31acfc7b1309fd0aaa1 (diff) | |
download | ale-5c839c482573263b4d3cb2bc4bc1719d49e14e22.zip |
#653 Collect items for quickfix from all buffers, and de-duplicate them. Set filename items in quickfix and loclist.
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/list.vim | 64 | ||||
-rw-r--r-- | autoload/ale/util.vim | 10 |
2 files changed, 70 insertions, 4 deletions
diff --git a/autoload/ale/list.vim b/autoload/ale/list.vim index e01f9e6d..6fe17d31 100644 --- a/autoload/ale/list.vim +++ b/autoload/ale/list.vim @@ -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() diff --git a/autoload/ale/util.vim b/autoload/ale/util.vim index 8eda8a98..969a19de 100644 --- a/autoload/ale/util.vim +++ b/autoload/ale/util.vim @@ -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 |