From 6d81660fd879532ddbb6203b7ad5275e68af9c57 Mon Sep 17 00:00:00 2001 From: Evgeny Firsov Date: Fri, 25 Dec 2015 21:10:55 -0800 Subject: [PATCH 1/2] Show YouCompleteMe error and warning count in the statusline Signed-off-by: Evgeny Firsov --- autoload/airline.vim | 2 +- autoload/airline/extensions.vim | 2 ++ autoload/airline/extensions/default.vim | 10 ++++--- autoload/airline/extensions/ycm.vim | 36 +++++++++++++++++++++++++ autoload/airline/init.vim | 5 +++- autoload/airline/themes.vim | 5 +++- 6 files changed, 53 insertions(+), 7 deletions(-) create mode 100644 autoload/airline/extensions/ycm.vim diff --git a/autoload/airline.vim b/autoload/airline.vim index 1d102320..e728b737 100644 --- a/autoload/airline.vim +++ b/autoload/airline.vim @@ -3,7 +3,7 @@ let g:airline_statusline_funcrefs = get(g:, 'airline_statusline_funcrefs', []) -let s:sections = ['a','b','c','gutter','x','y','z','warning'] +let s:sections = ['a','b','c','gutter','x','y','z', 'error', 'warning'] let s:inactive_funcrefs = [] function! airline#add_statusline_func(name) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index 4b1c80a1..3d1992c9 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -138,6 +138,8 @@ function! airline#extensions#load() call airline#extensions#netrw#init(s:ext) endif + call airline#extensions#ycm#init(s:ext) + if get(g:, 'loaded_vimfiler', 0) let g:vimfiler_force_overwrite_statusline = 0 endif diff --git a/autoload/airline/extensions/default.vim b/autoload/airline/extensions/default.vim index 51f1c0a2..3d6b56e6 100644 --- a/autoload/airline/extensions/default.vim +++ b/autoload/airline/extensions/default.vim @@ -9,7 +9,7 @@ let s:section_truncate_width = get(g:, 'airline#extensions#default#section_trunc \ }) let s:layout = get(g:, 'airline#extensions#default#layout', [ \ [ 'a', 'b', 'c' ], - \ [ 'x', 'y', 'z', 'warning' ] + \ [ 'x', 'y', 'z', 'error', 'warning' ] \ ]) function! s:get_section(winnr, key, ...) @@ -26,7 +26,7 @@ endfunction function! s:build_sections(builder, context, keys) for key in a:keys - if key == 'warning' && !a:context.active + if (key == 'warning' || key == 'error') && !a:context.active continue endif call s:add_section(a:builder, a:context, key) @@ -37,11 +37,11 @@ if v:version >= 704 || (v:version >= 703 && has('patch81')) function s:add_section(builder, context, key) " i have no idea why the warning section needs special treatment, but it's " needed to prevent separators from showing up - if a:key == 'warning' + if (a:key == 'warning' || a:key == 'error') call a:builder.add_raw('%(') endif call a:builder.add_section('airline_'.a:key, s:get_section(a:context.winnr, a:key)) - if a:key == 'warning' + if (a:key == 'warning' || a:key == 'error') call a:builder.add_raw('%)') endif endfunction @@ -50,6 +50,8 @@ else function s:add_section(builder, context, key) if a:key == 'warning' call a:builder.add_raw('%#airline_warning#'.s:get_section(a:context.winnr, a:key)) + else if a:key == 'error' + call a:builder.add_raw('%#airline_error#'.s:get_section(a:context.winnr, a:key)) else call a:builder.add_section('airline_'.a:key, s:get_section(a:context.winnr, a:key)) endif diff --git a/autoload/airline/extensions/ycm.vim b/autoload/airline/extensions/ycm.vim new file mode 100644 index 00000000..dc44c0e7 --- /dev/null +++ b/autoload/airline/extensions/ycm.vim @@ -0,0 +1,36 @@ +" MIT License. Copyright (c) 2015 Evgeny Firsov. +" vim: et ts=2 sts=2 sw=2 + +let s:spc = g:airline_symbols.space +let s:error_symbol = get(g:, 'airline#extensions#ycm#error_symbol', 'E:') +let s:warning_symbol = get(g:, 'airline#extensions#ycm#warning_symbol', 'W:') + +function! airline#extensions#ycm#init(ext) + call airline#parts#define_function('ycm_error_count', 'airline#extensions#ycm#get_error_count') + call airline#parts#define_function('ycm_warning_count', 'airline#extensions#ycm#get_warning_count') +endfunction + +function! airline#extensions#ycm#get_error_count() + if exists(':YcmDiag') + let cnt = youcompleteme#GetErrorCount() + + if cnt != 0 + return s:error_symbol.cnt + endif + endif + + return '' +endfunction + +function! airline#extensions#ycm#get_warning_count() + if exists(':YcmDiag') + let cnt = youcompleteme#GetWarningCount() + + if cnt != 0 + return s:warning_symbol.cnt.s:spc + endif + endif + + return '' +endfunction + diff --git a/autoload/airline/init.vim b/autoload/airline/init.vim index 9b1d5fe0..b467c7cb 100644 --- a/autoload/airline/init.vim +++ b/autoload/airline/init.vim @@ -110,8 +110,11 @@ function! airline#init#sections() if !exists('g:airline_section_z') let g:airline_section_z = airline#section#create(['windowswap', '%3p%%'.spc, 'linenr', ':%3v ']) endif + if !exists('g:airline_section_error') + let g:airline_section_error = airline#section#create(['ycm_error_count']) + endif if !exists('g:airline_section_warning') - let g:airline_section_warning = airline#section#create(['syntastic', 'eclim', 'whitespace']) + let g:airline_section_warning = airline#section#create(['ycm_warning_count', 'syntastic', 'eclim', 'whitespace']) endif endfunction diff --git a/autoload/airline/themes.vim b/autoload/airline/themes.vim index 9387954e..2f0315c9 100644 --- a/autoload/airline/themes.vim +++ b/autoload/airline/themes.vim @@ -37,7 +37,10 @@ endfunction function! airline#themes#patch(palette) for mode in keys(a:palette) if !has_key(a:palette[mode], 'airline_warning') - let a:palette[mode]['airline_warning'] = [ '#000000', '#df5f00', 232, 166 ] + let a:palette[mode]['airline_warning'] = [ '#000000', '#df5f00', 232, 190 ] + endif + if !has_key(a:palette[mode], 'airline_error') + let a:palette[mode]['airline_error'] = [ '#000000', '#df5f00', 232, 160 ] endif endfor From 2711863088294063931a028c9161e305cc57dba9 Mon Sep 17 00:00:00 2001 From: Evgeny Firsov Date: Thu, 28 Jan 2016 00:40:27 -0800 Subject: [PATCH 2/2] Added documentation for YCM extenstion Signed-off-by: Evgeny Firsov --- doc/airline.txt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/airline.txt b/doc/airline.txt index 9b5f00f8..02855ccb 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -225,7 +225,8 @@ section. let g:airline_section_x (tagbar, filetype, virtualenv) let g:airline_section_y (fileencoding, fileformat) let g:airline_section_z (percentage, line number, column number) - let g:airline_section_warning (syntastic, whitespace) + let g:airline_section_error (ycm_error_count) + let g:airline_section_warning (ycm_warning_count, syntastic, whitespace) " here is an example of how you could replace the branch indicator with " the current working directory, followed by the filename. @@ -275,7 +276,7 @@ configuration values that you can use. (first array is the left side, second array is the right side). > let g:airline#extensions#default#layout = [ \ [ 'a', 'b', 'c' ], - \ [ 'x', 'y', 'z', 'warning' ] + \ [ 'x', 'y', 'z', 'error', 'warning' ] \ ] < ------------------------------------- *airline-quickfix* @@ -625,6 +626,17 @@ vim-ctrlspace * enable/disable vim-ctrlspace integration > let g:airline#extensions#ctrlspace#enabled = 1 < +------------------------------------- *airline-ycm* +YouCompleteMe + +Shows number of errors and warnings in the current file detected by YCM. + +* set error count prefix > + let g:airline#extensions#ycm#error_symbol = 'E:' + +* set warning count prefix > + let g:airline#extensions#ycm#warning_symbol = 'W:' +< ============================================================================== ADVANCED CUSTOMIZATION *airline-advanced-customization*