Commit f436a5f5 authored by Hauleth's avatar Hauleth

Reduce amount of signs

This should greatly reduced amount of created signs by grouping errors
by line and picking only the most important ones to show as a signs.
parent ab0794aa
let s:sign_count = get(s:, 'sign_count', 0)
function! qfx#place() abort
if s:sign_count > 0
return
let s:importance_table = {'E': 0, 'W': 1}
let s:sign_names = ['QFxError', 'QFxWarn', 'QFxInfo']
function! s:min(a, b) abort
if a:a < 0
return a:b
elseif a:b < 0
return a:a
elseif a:a < a:b
return a:a
else
return a:b
endif
endfunction
function! s:importance(elem) abort
return get(s:importance_table, a:elem, 999)
endfunction
function! s:reduce(list) abort
let l:errors = {}
let l:qflist = getqflist()
for l:error in a:list
if l:error.bufnr < 0 | continue | endif
let l:errors[l:error.bufnr] = get(l:errors, l:error.bufnr, {})
let l:current = get(l:errors[l:error.bufnr], l:error.lnum, -1)
let l:errors[l:error.bufnr][l:error.lnum] =
\ s:min(l:current, s:importance(l:error.type))
endfor
let l:ret = []
for l:bufnr in keys(l:errors)
for l:lnum in keys(l:errors[l:bufnr])
call add(l:ret, {
\ 'bufnr': l:bufnr,
\ 'lnum': l:lnum,
\ 'level': l:errors[l:bufnr][l:lnum]
\ })
endfor
endfor
return l:ret
endfunction
function! qfx#place() abort
if s:sign_count > 0 | return | endif
let l:qflist = s:reduce(getqflist())
if len(l:qflist) > get(g:, 'qfx_signs_max', 200)
echohl ErrorMsg
......@@ -20,17 +64,9 @@ function! qfx#place() abort
let s:sign_count = s:sign_count + 1
if l:error.type ==# 'E'
let l:type = 'QFxErr'
elseif l:error.type ==# 'W'
let l:type = 'QFxWarn'
else
let l:type = 'QFxInfo'
endif
let l:err_sign = 'sign place ' . s:sign_count
\ . ' line=' . l:error.lnum
\ . ' name=' . l:type
\ . ' name=' . get(s:sign_names, l:error.level, s:sign_names[-1])
\ . ' buffer=' . l:error.bufnr
silent! execute l:err_sign
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment