coc: add in coc_status to coc.nvim integration

Allow to show additional messages from coc.nvim in section_c

For ease of use, shorten the message for windows smaller than 81
characters.

closes #2079
This commit is contained in:
ckipp01 2020-02-28 00:06:00 +01:00 committed by Christian Brabandt
parent fdafa44b2f
commit fe94d52c4c
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
3 changed files with 19 additions and 8 deletions

View File

@ -7,16 +7,16 @@ scriptencoding utf-8
let s:error_symbol = get(g:, 'airline#extensions#coc#error_symbol', 'E:') 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:warning_symbol = get(g:, 'airline#extensions#coc#warning_symbol', 'W:')
function! airline#extensions#coc#get_warning() function! airline#extensions#coc#get_warning() abort
return airline#extensions#coc#get('warning') return airline#extensions#coc#get('warning')
endfunction endfunction
function! airline#extensions#coc#get_error() function! airline#extensions#coc#get_error() abort
return airline#extensions#coc#get('error') return airline#extensions#coc#get('error')
endfunction endfunction
function! airline#extensions#coc#get(type) function! airline#extensions#coc#get(type) abort
if !exists(":CocCommand") if !exists(':CocCommand')
return '' return ''
endif endif
let _backup = get(g:, 'coc_stl_format', '') let _backup = get(g:, 'coc_stl_format', '')
@ -42,7 +42,13 @@ function! airline#extensions#coc#get(type)
endif endif
endfunction endfunction
function! airline#extensions#coc#init(ext) function! airline#extensions#coc#get_status() abort
" Shorten text for windows < 81 characters
return airline#util#shorten(get(g:, 'coc_status', ''), 81, 9)
endfunction
function! airline#extensions#coc#init(ext) abort
call airline#parts#define_function('coc_error_count', 'airline#extensions#coc#get_error') 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') call airline#parts#define_function('coc_warning_count', 'airline#extensions#coc#get_warning')
call airline#parts#define_function('coc_status', 'airline#extensions#coc#get_status')
endfunction endfunction

View File

@ -161,6 +161,10 @@ function! airline#init#bootstrap()
call airline#parts#define('branch', { call airline#parts#define('branch', {
\ 'raw': '', \ 'raw': '',
\ 'minwidth': 80}) \ 'minwidth': 80})
call airline#parts#define('coc_status', {
\ 'raw': '',
\ 'accent': 'airline_term'
\ })
call airline#parts#define_empty(['obsession', 'tagbar', 'syntastic-warn', call airline#parts#define_empty(['obsession', 'tagbar', 'syntastic-warn',
\ 'syntastic-err', 'eclim', 'whitespace','windowswap', \ 'syntastic-err', 'eclim', 'whitespace','windowswap',
\ 'ycm_error_count', 'ycm_warning_count', 'neomake_error_count', \ 'ycm_error_count', 'ycm_warning_count', 'neomake_error_count',
@ -194,7 +198,7 @@ function! airline#init#sections()
if exists("+autochdir") && &autochdir == 1 if exists("+autochdir") && &autochdir == 1
let g:airline_section_c = airline#section#create(['%<', 'path', spc, 'readonly']) let g:airline_section_c = airline#section#create(['%<', 'path', spc, 'readonly'])
else else
let g:airline_section_c = airline#section#create(['%<', 'file', spc, 'readonly']) let g:airline_section_c = airline#section#create(['%<', 'file', spc, 'readonly', 'coc_status'])
endif endif
endif endif
if !exists('g:airline_section_gutter') if !exists('g:airline_section_gutter')

View File

@ -29,8 +29,8 @@ describe 'init sections'
Expect g:airline_section_b == '' Expect g:airline_section_b == ''
end end
it 'section c should be file' it 'section c should be file and coc_status'
Expect g:airline_section_c == '%<%f%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#' Expect g:airline_section_c == '%<%f%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#%#__accent_airline_term#%#__restore__#'
end end
it 'section x should be filetype' it 'section x should be filetype'
@ -78,6 +78,7 @@ describe 'init sections'
Expect airline#parts#get('ycm_warning_count').raw == '' Expect airline#parts#get('ycm_warning_count').raw == ''
Expect airline#parts#get('languageclient_error_count').raw == '' Expect airline#parts#get('languageclient_error_count').raw == ''
Expect airline#parts#get('languageclient_warning_count').raw == '' Expect airline#parts#get('languageclient_warning_count').raw == ''
Expect airline#parts#get('coc_status').raw == ''
end end
end end