Skip to content

Commit

Permalink
coc: Show the current function in section_x
Browse files Browse the repository at this point in the history
coc.nvim exposes the name of the function the cursor is currently in
through b:coc_current_function.

For this to work, the key coc.preferences.currentFunctionSymbolAutoUpdate
must be set to 'true' in the coc config.

The value is only updated on CursorHold, so the value may not always be
accurate when moving around.
  • Loading branch information
patrick96 committed Mar 19, 2021
1 parent 09dbd09 commit 7d6adf9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -20,7 +20,7 @@ This is the Changelog for the vim-airline project.
- [gen_tags.vim](https://github.com/jsfaint/gen_tags.vim) support
- Improvements
- git branch can also be displayed using [gina.vim](https://github.com/lambdalisue/gina.vim)
- coc extensions can also show additional status messages
- coc extensions can also show additional status messages as well as the current function
- [coc-git](https://github.com/neoclide/coc-git) extension integrated into hunks extension
- Other
- Changed CI from travis-ci.org to GitHub Actions
Expand Down
5 changes: 5 additions & 0 deletions autoload/airline/extensions/coc.vim
Expand Up @@ -48,8 +48,13 @@ function! airline#extensions#coc#get_status() abort
return airline#util#shorten(get(g:, 'coc_status', ''), 91, 9)
endfunction

function! airline#extensions#coc#get_current_function() abort
return get(b:, 'coc_current_function', '')
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_warning_count', 'airline#extensions#coc#get_warning')
call airline#parts#define_function('coc_status', 'airline#extensions#coc#get_status')
call airline#parts#define_function('coc_current_function', 'airline#extensions#coc#get_current_function')
endfunction
6 changes: 5 additions & 1 deletion autoload/airline/init.vim
Expand Up @@ -164,6 +164,10 @@ function! airline#init#bootstrap()
\ 'raw': '',
\ 'accent': 'bold'
\ })
call airline#parts#define('coc_current_function', {
\ 'raw': '',
\ 'accent': 'bold'
\ })
call airline#parts#define('lsp_progress', {
\ 'raw': '',
\ 'accent': 'bold'
Expand Down Expand Up @@ -211,7 +215,7 @@ function! airline#init#sections()
let g:airline_section_gutter = airline#section#create(['%='])
endif
if !exists('g:airline_section_x')
let g:airline_section_x = airline#section#create_right(['bookmark', 'tagbar', 'vista', 'gutentags', 'gen_tags', 'omnisharp', 'grepper', 'filetype'])
let g:airline_section_x = airline#section#create_right(['coc_current_function', 'bookmark', 'tagbar', 'vista', 'gutentags', 'gen_tags', 'omnisharp', 'grepper', 'filetype'])
endif
if !exists('g:airline_section_y')
let g:airline_section_y = airline#section#create_right(['ffenc'])
Expand Down
3 changes: 2 additions & 1 deletion t/init.vim
Expand Up @@ -34,7 +34,7 @@ describe 'init sections'
end

it 'section x should be filetype'
Expect g:airline_section_x == '%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#wrap(airline#parts#filetype(),0)}'
Expect g:airline_section_x == '%#__accent_bold#%#__restore__#%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#prepend("",0)}%{airline#util#wrap(airline#parts#filetype(),0)}'
end

it 'section y should be fenc and ff'
Expand Down Expand Up @@ -81,6 +81,7 @@ describe 'init sections'
Expect airline#parts#get('languageclient_error_count').raw == ''
Expect airline#parts#get('languageclient_warning_count').raw == ''
Expect airline#parts#get('coc_status').raw == ''
Expect airline#parts#get('coc_current_function').raw == ''
Expect airline#parts#get('vista').raw == ''
Expect airline#parts#get('coc_warning_count').raw == ''
Expect airline#parts#get('coc_error_count').raw == ''
Expand Down

0 comments on commit 7d6adf9

Please sign in to comment.