Improve coc error/warning status format to include count

This commit is contained in:
eximus 2022-11-04 13:47:07 -04:00
parent d734be8cd3
commit b86e5e09b2
2 changed files with 16 additions and 21 deletions

View File

@ -4,8 +4,6 @@
scriptencoding utf-8
let s:error_symbol = get(g:, 'airline#extensions#coc#error_symbol', 'E:')
let s:warning_symbol = get(g:, 'airline#extensions#coc#warning_symbol', 'W:')
let s:show_coc_status = get(g:, 'airline#extensions#coc#show_coc_status', 1)
function! airline#extensions#coc#get_warning() abort
@ -17,28 +15,25 @@ function! airline#extensions#coc#get_error() abort
endfunction
function! airline#extensions#coc#get(type) abort
if !exists(':CocCommand')
return ''
endif
if !exists(':CocCommand') | return '' | endif
let is_err = (a:type is# 'error')
let info = get(b:, 'coc_diagnostic_info', {})
if empty(info) | return '' | endif
if is_err
let format = get(g:, 'airline#extensions#coc#stl_format_err', '(L%d)')
else
let format = get(g:, 'airline#extensions#coc#stl_format_warn', '(L%d)')
endif
let cnt = get(info, a:type, 0)
if empty(cnt) | return '' | endif
if empty(cnt)
return ''
else
let lnum = printf(format, (info.lnums)[is_err ? 0 : 1])
return (is_err ? s:error_symbol : s:warning_symbol).cnt.lnum
endif
let error_symbol = get(g:, 'airline#extensions#coc#error_symbol', 'E:')
let warning_symbol = get(g:, 'airline#extensions#coc#warning_symbol', 'W:')
let error_format = get(g:, 'airline#extensions#coc#stl_format_err', '%C(L%L)')
let warning_format = get(g:, 'airline#extensions#coc#stl_format_warn', '%C(L%L)')
" replace %C with error count and %L with line number
return (is_err ? error_symbol : warning_symbol) .
\ substitute(substitute(is_err ? error_format : warning_format,
\ '%C', cnt, 'g'),
\ '%L', (info.lnums)[is_err ? 0 : 1], 'g')
endfunction
function! airline#extensions#coc#get_status() abort

View File

@ -650,11 +650,11 @@ coc <https://github.com/neoclide/coc.nvim>
* enable/disable coc status display >
g:airline#extensions#coc#show_coc_status = 1
* change the error format: >
let airline#extensions#coc#stl_format_err = '(L%d)'
* change the error format (%C - error count, %L - line number): >
let airline#extensions#coc#stl_format_err = '%C(L%L)'
<
* change the warning format: >
let airline#extensions#coc#stl_format_warn = '(L%d)'
* change the warning format (%C - error count, %L - line number): >
let airline#extensions#coc#stl_format_warn = '%C(L%L)'
<
------------------------------------- *airline-commandt*
command-t <https://github.com/wincent/command-t>