2021-01-01 20:57:00 +08:00
|
|
|
" MIT License. Copyright (c) 2019-2021 Peng Guanwen et al.
|
2019-11-09 03:18:04 +08:00
|
|
|
" vim: et ts=2 sts=2 sw=2
|
|
|
|
" Plugin: https://github.com/neoclide/coc
|
|
|
|
|
2019-05-30 03:04:32 +08:00
|
|
|
scriptencoding utf-8
|
2019-05-29 15:59:00 +08:00
|
|
|
|
|
|
|
let s:error_symbol = get(g:, 'airline#extensions#coc#error_symbol', 'E:')
|
|
|
|
let s:warning_symbol = get(g:, 'airline#extensions#coc#warning_symbol', 'W:')
|
|
|
|
|
2020-02-28 07:06:00 +08:00
|
|
|
function! airline#extensions#coc#get_warning() abort
|
2019-05-29 15:59:00 +08:00
|
|
|
return airline#extensions#coc#get('warning')
|
|
|
|
endfunction
|
|
|
|
|
2020-02-28 07:06:00 +08:00
|
|
|
function! airline#extensions#coc#get_error() abort
|
2019-05-29 15:59:00 +08:00
|
|
|
return airline#extensions#coc#get('error')
|
|
|
|
endfunction
|
|
|
|
|
2020-02-28 07:06:00 +08:00
|
|
|
function! airline#extensions#coc#get(type) abort
|
|
|
|
if !exists(':CocCommand')
|
2019-05-30 03:04:32 +08:00
|
|
|
return ''
|
|
|
|
endif
|
2019-05-29 15:59:00 +08:00
|
|
|
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
|
2021-02-28 15:30:17 +08:00
|
|
|
let lnum = printf('(L%d)', (info.lnums)[0])
|
|
|
|
return (is_err ? s:error_symbol : s:warning_symbol).cnt.lnum
|
2019-05-29 15:59:00 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2020-02-28 07:06:00 +08:00
|
|
|
function! airline#extensions#coc#get_status() abort
|
2020-04-18 16:48:26 +08:00
|
|
|
" Shorten text for windows < 91 characters
|
|
|
|
return airline#util#shorten(get(g:, 'coc_status', ''), 91, 9)
|
2020-02-28 07:06:00 +08:00
|
|
|
endfunction
|
|
|
|
|
2021-03-20 07:42:46 +08:00
|
|
|
function! airline#extensions#coc#get_current_function() abort
|
|
|
|
return get(b:, 'coc_current_function', '')
|
|
|
|
endfunction
|
|
|
|
|
2020-02-28 07:06:00 +08:00
|
|
|
function! airline#extensions#coc#init(ext) abort
|
2019-05-29 15:59:00 +08:00
|
|
|
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')
|
2020-02-28 07:06:00 +08:00
|
|
|
call airline#parts#define_function('coc_status', 'airline#extensions#coc#get_status')
|
2021-03-20 07:42:46 +08:00
|
|
|
call airline#parts#define_function('coc_current_function', 'airline#extensions#coc#get_current_function')
|
2019-05-29 15:59:00 +08:00
|
|
|
endfunction
|