#653 - Include the buffer number in sorting of items

This commit is contained in:
w0rp 2017-08-12 14:37:56 +01:00
parent c52a4910bf
commit c14886e479
2 changed files with 30 additions and 12 deletions

View File

@ -22,19 +22,27 @@ function! ale#util#GetFunction(string_or_ref) abort
endfunction endfunction
function! ale#util#LocItemCompare(left, right) abort function! ale#util#LocItemCompare(left, right) abort
if a:left['lnum'] < a:right['lnum'] if a:left.bufnr < a:right.bufnr
return -1 return -1
endif endif
if a:left['lnum'] > a:right['lnum'] if a:left.bufnr > a:right.bufnr
return 1 return 1
endif endif
if a:left['col'] < a:right['col'] if a:left.lnum < a:right.lnum
return -1 return -1
endif endif
if a:left['col'] > a:right['col'] if a:left.lnum > a:right.lnum
return 1
endif
if a:left.col < a:right.col
return -1
endif
if a:left.col > a:right.col
return 1 return 1
endif endif

View File

@ -1,9 +1,14 @@
Before: Before:
let g:loclist = [ let g:loclist = [
\ {'lnum': 5, 'col': 5}, \ {'bufnr': 3, 'lnum': 1, 'col': 1},
\ {'lnum': 5, 'col': 4}, \ {'bufnr': 1, 'lnum': 5, 'col': 5},
\ {'lnum': 2, 'col': 10}, \ {'bufnr': 2, 'lnum': 5, 'col': 5},
\ {'lnum': 3, 'col': 2}, \ {'bufnr': 1, 'lnum': 5, 'col': 4},
\ {'bufnr': 1, 'lnum': 2, 'col': 10},
\ {'bufnr': 2, 'lnum': 1, 'col': 5},
\ {'bufnr': 1, 'lnum': 3, 'col': 2},
\ {'bufnr': 2, 'lnum': 1, 'col': 2},
\ {'bufnr': -1, 'lnum': 3, 'col': 2},
\] \]
Execute (Sort loclist with comparison function): Execute (Sort loclist with comparison function):
@ -11,10 +16,15 @@ Execute (Sort loclist with comparison function):
Then (loclist item should be sorted): Then (loclist item should be sorted):
AssertEqual [ AssertEqual [
\ {'lnum': 2, 'col': 10}, \ {'bufnr': -1, 'lnum': 3, 'col': 2},
\ {'lnum': 3, 'col': 2}, \ {'bufnr': 1, 'lnum': 2, 'col': 10},
\ {'lnum': 5, 'col': 4}, \ {'bufnr': 1, 'lnum': 3, 'col': 2},
\ {'lnum': 5, 'col': 5}, \ {'bufnr': 1, 'lnum': 5, 'col': 4},
\ {'bufnr': 1, 'lnum': 5, 'col': 5},
\ {'bufnr': 2, 'lnum': 1, 'col': 2},
\ {'bufnr': 2, 'lnum': 1, 'col': 5},
\ {'bufnr': 2, 'lnum': 5, 'col': 5},
\ {'bufnr': 3, 'lnum': 1, 'col': 1},
\], g:loclist \], g:loclist
After: After: