mirror of
https://github.com/dense-analysis/ale.git
synced 2026-01-21 02:22:13 +08:00
Print the most severe problem with virtualtext
Fix the ordering of virtualtext so we print the most severe problem on a line. If two problems are the most severe, we will print the left-most problem.
This commit is contained in:
@@ -274,6 +274,32 @@ function! ale#virtualtext#ShowCursorWarningWithDelay() abort
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! ale#virtualtext#CompareSeverityPerLine(left, right) abort
|
||||
" Compare lines
|
||||
if a:left.lnum < a:right.lnum
|
||||
return -1
|
||||
endif
|
||||
|
||||
if a:left.lnum > a:right.lnum
|
||||
return 1
|
||||
endif
|
||||
|
||||
let l:left_priority = ale#util#GetItemPriority(a:left)
|
||||
let l:right_priority = ale#util#GetItemPriority(a:right)
|
||||
|
||||
" Put highest priority items first.
|
||||
if l:left_priority > l:right_priority
|
||||
return -1
|
||||
endif
|
||||
|
||||
if l:left_priority < l:right_priority
|
||||
return 1
|
||||
endif
|
||||
|
||||
" Put the first seen problem first.
|
||||
return a:left.col - a:right.col
|
||||
endfunction
|
||||
|
||||
function! ale#virtualtext#SetTexts(buffer, loclist) abort
|
||||
if !has('nvim') && s:emulate_virt
|
||||
return
|
||||
@@ -281,17 +307,19 @@ function! ale#virtualtext#SetTexts(buffer, loclist) abort
|
||||
|
||||
call ale#virtualtext#Clear(a:buffer)
|
||||
|
||||
let l:filter = ale#Var(a:buffer,'virtualtext_single')
|
||||
let l:seen = {}
|
||||
let l:buffer_list = filter(copy(a:loclist), 'v:val.bufnr == a:buffer')
|
||||
|
||||
for l:item in a:loclist
|
||||
if l:item.bufnr == a:buffer
|
||||
let l:line = max([1, l:item.lnum])
|
||||
if ale#Var(a:buffer,'virtualtext_single')
|
||||
" If we want a single problem per line, sort items on each line by
|
||||
" highest severity and then lowest column position, then de-duplicate
|
||||
" the items by line.
|
||||
call uniq(
|
||||
\ sort(l:buffer_list, function('ale#virtualtext#CompareSeverityPerLine')),
|
||||
\ {a, b -> a.lnum - b.lnum}
|
||||
\)
|
||||
endif
|
||||
|
||||
if !has_key(l:seen,l:line) || l:filter == 0
|
||||
call ale#virtualtext#ShowMessage(a:buffer, l:item)
|
||||
let l:seen[l:line] = 1
|
||||
endif
|
||||
endif
|
||||
for l:item in l:buffer_list
|
||||
call ale#virtualtext#ShowMessage(a:buffer, l:item)
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user