From b86e5e09b2c8ea572349094191dc134b3dd5e344 Mon Sep 17 00:00:00 2001 From: eximus Date: Fri, 4 Nov 2022 13:47:07 -0400 Subject: [PATCH] Improve coc error/warning status format to include count --- autoload/airline/extensions/coc.vim | 29 ++++++++++++----------------- doc/airline.txt | 8 ++++---- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/autoload/airline/extensions/coc.vim b/autoload/airline/extensions/coc.vim index 79d3a4af..38259646 100644 --- a/autoload/airline/extensions/coc.vim +++ b/autoload/airline/extensions/coc.vim @@ -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 diff --git a/doc/airline.txt b/doc/airline.txt index 5bd1a3e8..179127e6 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -650,11 +650,11 @@ coc * 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