hunks: integrate coc-git extension

The coc-git extension to coc does show similar statistics as e.g.
gitgutter, therefore, integrate the coc-git interface into the hunk
extension.

closes #2094
This commit is contained in:
Christian Brabandt 2020-03-29 17:28:15 +02:00
parent 02a0ab4b59
commit a13bed2f51
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
3 changed files with 27 additions and 2 deletions

View File

@ -10,6 +10,7 @@ This is the Changelog for the vim-airline project.
- 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-git](https://github.com/neoclide/coc-git) extension integrated into hunks extension
- Other
- Introduce Vim script static analysis using [reviewdog](https://github.com/reviewdog/action-vint)
- Added multiple Vim versions to unit tests using Travis CI

View File

@ -1,10 +1,10 @@
" MIT License. Copyright (c) 2013-2019 Bailey Ling et al.
" Plugin: vim-gitgutter, vim-signify, changesPlugin, quickfixsigns
" Plugin: vim-gitgutter, vim-signify, changesPlugin, quickfixsigns, coc-git
" vim: et ts=2 sts=2 sw=2
scriptencoding utf-8
if !get(g:, 'loaded_signify', 0) && !get(g:, 'loaded_gitgutter', 0) && !get(g:, 'loaded_changes', 0) && !get(g:, 'loaded_quickfixsigns', 0)
if !get(g:, 'loaded_signify', 0) && !get(g:, 'loaded_gitgutter', 0) && !get(g:, 'loaded_changes', 0) && !get(g:, 'loaded_quickfixsigns', 0) && !empty(get(g:, 'coc_git_status',''))
finish
endif
@ -19,6 +19,24 @@ function! s:get_hunks_signify()
return []
endfunction
function! s:get_hunks_coc()
let hunks = get(b:, 'coc_git_status', '')
if empty(hunks)
return []
endif
let result = [0, 0, 0]
for val in split(hunks)
if val[0] is# '+'
let result[0] = val[1:] + 0
elseif val[0] is# '~'
let result[1] = val[1:] + 0
elseif val[0] is# '-'
let result[2] = val[1:] + 0
endif
endfor
return result
endfunction
function! s:is_branch_empty()
return exists('*airline#extensions#branch#head') &&
\ empty(get(b:, 'airline_head', ''))
@ -53,9 +71,13 @@ function! airline#extensions#hunks#get_raw_hunks()
let b:source_func = 's:get_hunks_changes'
elseif exists('*quickfixsigns#vcsdiff#GetHunkSummary')
let b:source_func = 'quickfixsigns#vcsdiff#GetHunkSummary'
elseif exists("g:coc_git_status")
let b:source_func = 's:get_hunks_coc'
else
let b:source_func = 's:get_hunks_empty'
endif
else
let b:source_func = 's:get_hunks_empty'
endif
return {b:source_func}()
endfunction
@ -78,6 +100,7 @@ function! airline#extensions#hunks#get_hunks()
let string = ''
let winwidth = get(airline#parts#get('hunks'), 'minwidth', 100)
if !empty(hunks)
" hunks should contain [added, changed, deleted]
for i in [0, 1, 2]
if (s:non_zero_only == 0 && airline#util#winwidth() > winwidth) || hunks[i] > 0
let string .= printf('%s%s ', s:hunk_symbols[i], hunks[i])

View File

@ -738,6 +738,7 @@ vim-gitgutter <https://github.com/airblade/vim-gitgutter>
vim-signify <https://github.com/mhinz/vim-signify>
changesPlugin <https://github.com/chrisbra/changesPlugin>
quickfixsigns <https://github.com/tomtom/quickfixsigns_vim>
coc-git <https://github.com/neoclide/coc-git>
You can use `airline#extensions#hunks#get_raw_hunks()` to get the full hunks,
without shortening. This allows for advanced customization, or a quick way of