diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 84fcdda..112abf8 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -272,6 +272,11 @@ function! airline#extensions#load() call add(s:loaded_ext, 'ale') endif + if (get(g:, 'airline#extensions#coc#enabled', 1) && exists(':CocCommand')) + call airline#extensions#coc#init(s:ext) + call add(s:loaded_ext, 'coc') + endif + if (get(g:, 'airline#extensions#languageclient#enabled', 1) && exists(':LanguageClientStart')) call airline#extensions#languageclient#init(s:ext) call add(s:loaded_ext, 'languageclient') diff --git a/autoload/airline/extensions/coc.vim b/autoload/airline/extensions/coc.vim new file mode 100644 index 0000000..9ae7857 --- /dev/null +++ b/autoload/airline/extensions/coc.vim @@ -0,0 +1,40 @@ + +let s:error_symbol = get(g:, 'airline#extensions#coc#error_symbol', 'E:') +let s:warning_symbol = get(g:, 'airline#extensions#coc#warning_symbol', 'W:') + +function! airline#extensions#coc#get_warning() + return airline#extensions#coc#get('warning') +endfunction + +function! airline#extensions#coc#get_error() + return airline#extensions#coc#get('error') +endfunction + +function! airline#extensions#coc#get(type) + let _backup = get(g:, 'coc_stl_format', '') + let is_err = (a:type is# 'error') + if is_err + let g:coc_stl_format = get(g:, 'airline#extensions#coc#stl_format_err', '%E{[%e(#%fe)]}') + else + let g:coc_stl_format = get(g:, 'airline#extensions#coc#stl_format_warn', '%W{[%w(#%fw)]}') + endif + let info = get(b:, 'coc_diagnostic_info', {}) + if empty(info) | return '' | endif + + + let cnt = get(info, a:type, 0) + if !empty(_backup) + let g:coc_stl_format = _backup + endif + + if empty(cnt) + return '' + else + return (is_err ? s:error_symbol : s:warning_symbol).cnt + endif +endfunction + +function! airline#extensions#coc#init(ext) + call airline#parts#define_function('coc_error_count', 'airline#extensions#coc#get_error') + call airline#parts#define_function('coc_warning_count', 'airline#extensions#coc#get_warning') +endfunction diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 3636434..1d5d26f 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -211,9 +211,9 @@ function! airline#init#sections() endif endif if !exists('g:airline_section_error') - let g:airline_section_error = airline#section#create(['ycm_error_count', 'syntastic-err', 'eclim', 'neomake_error_count', 'ale_error_count', 'languageclient_error_count']) + let g:airline_section_error = airline#section#create(['ycm_error_count', 'syntastic-err', 'eclim', 'neomake_error_count', 'ale_error_count', 'languageclient_error_count', 'coc_error_count']) endif if !exists('g:airline_section_warning') - let g:airline_section_warning = airline#section#create(['ycm_warning_count', 'syntastic-warn', 'neomake_warning_count', 'ale_warning_count', 'languageclient_warning_count', 'whitespace']) + let g:airline_section_warning = airline#section#create(['ycm_warning_count', 'syntastic-warn', 'neomake_warning_count', 'ale_warning_count', 'languageclient_warning_count', 'whitespace', 'coc_warning_count']) endif endfunction diff --git a/doc/airline.txt b/doc/airline.txt index b8bbcbb..f57ffd3 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -546,6 +546,24 @@ vim-capslock * enable/disable vim-capslock integration > let g:airline#extensions#capslock#enabled = 1 +------------------------------------- *airline-coc* +coc + +* enable/disable coc integration > + let g:airline#extensions#coc#enabled = 1 +< +* change error symbol: > + let airline#extensions#coc#error_symbol = 'E:' +< +* change warning symbol: > + let airline#extensions#coc#warning_symbol = 'W:' +< +* change error format: > + let airline#extensions#coc#stl_format_err = '%E{[%e(#%fe)]}' +< +* change warning format: > + let airline#extensions#coc#stl_format_warn = '%W{[%w(#%fw)]}' + ------------------------------------- *airline-csv* csv.vim