mirror of
https://github.com/vim-airline/vim-airline.git
synced 2024-11-22 09:58:29 +08:00
hunks: add support for gitsigns.nvim
Refactor s:get_hunks_coc() so that parsing the hunk status can be reused by s:get_hunks_gitsigns(). Reorder s:get_hunks_coc() for consistent ordering with related code. Give gitsigns.nvim priority over coc-git when selecting b:source_func in hunks#get_raw_hunks().
This commit is contained in:
parent
9e2d021fc6
commit
46f0a12bae
|
@ -163,7 +163,7 @@ vim-airline integrates with a variety of plugins out of the box. These extensio
|
|||
#### [syntastic][5]
|
||||
![image](https://f.cloud.github.com/assets/306502/962864/9824c484-04f7-11e3-9928-da94f8c7da5a.png)
|
||||
|
||||
#### hunks ([vim-gitgutter][29] & [vim-signify][30] & [coc-git][59])
|
||||
#### hunks ([vim-gitgutter][29], [vim-signify][30], [coc-git][59] & [gitsigns.nvim][63])
|
||||
![image](https://f.cloud.github.com/assets/306502/995185/73fc7054-09b9-11e3-9d45-618406c6ed98.png)
|
||||
|
||||
#### [vimagit][50]
|
||||
|
@ -369,3 +369,4 @@ If you are interested in becoming a maintainer (we always welcome more maintaine
|
|||
[60]: https://github.com/cdelledonne/vim-cmake
|
||||
[61]: http://github.com/lambdalisue/battery.vim/
|
||||
[62]: http://github.com/rbong/vim-flog/
|
||||
[63]: https://github.com/lewis6991/gitsigns.nvim
|
||||
|
|
|
@ -234,6 +234,7 @@ function! airline#extensions#load()
|
|||
\ || exists('g:loaded_gitgutter')
|
||||
\ || exists('g:loaded_changes')
|
||||
\ || exists('g:loaded_quickfixsigns')
|
||||
\ || exists(':Gitsigns')
|
||||
\ || exists(':CocCommand'))
|
||||
call airline#extensions#hunks#init(s:ext)
|
||||
call add(s:loaded_ext, 'hunks')
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
" MIT License. Copyright (c) 2013-2021 Bailey Ling et al.
|
||||
" Plugin: vim-gitgutter, vim-signify, changesPlugin, quickfixsigns, coc-git
|
||||
" Plugin: vim-gitgutter, vim-signify, changesPlugin, quickfixsigns, coc-git,
|
||||
" gitsigns.nvim
|
||||
" vim: et ts=2 sts=2 sw=2
|
||||
|
||||
scriptencoding utf-8
|
||||
|
@ -8,6 +9,7 @@ if !get(g:, 'loaded_signify', 0)
|
|||
\ && !get(g:, 'loaded_gitgutter', 0)
|
||||
\ && !get(g:, 'loaded_changes', 0)
|
||||
\ && !get(g:, 'loaded_quickfixsigns', 0)
|
||||
\ && !exists(':Gitsigns')
|
||||
\ && !exists("*CocAction")
|
||||
finish
|
||||
endif
|
||||
|
@ -26,21 +28,12 @@ function! s:coc_git_enabled() abort
|
|||
return 1
|
||||
endfunction
|
||||
|
||||
function! s:get_hunks_signify() abort
|
||||
let hunks = sy#repo#get_stats()
|
||||
if hunks[0] >= 0
|
||||
return hunks
|
||||
endif
|
||||
return []
|
||||
endfunction
|
||||
|
||||
function! s:get_hunks_coc() abort
|
||||
let hunks = get(b:, 'coc_git_status', '')
|
||||
if empty(hunks)
|
||||
function! s:parse_hunk_status(hunks) abort
|
||||
if empty(a:hunks)
|
||||
return []
|
||||
endif
|
||||
let result = [0, 0, 0]
|
||||
for val in split(hunks)
|
||||
for val in split(a:hunks)
|
||||
if val[0] is# '+'
|
||||
let result[0] = val[1:] + 0
|
||||
elseif val[0] is# '~'
|
||||
|
@ -52,6 +45,14 @@ function! s:get_hunks_coc() abort
|
|||
return result
|
||||
endfunction
|
||||
|
||||
function! s:get_hunks_signify() abort
|
||||
let hunks = sy#repo#get_stats()
|
||||
if hunks[0] >= 0
|
||||
return hunks
|
||||
endif
|
||||
return []
|
||||
endfunction
|
||||
|
||||
function! s:get_hunks_gitgutter() abort
|
||||
let hunks = GitGutterGetHunkSummary()
|
||||
return hunks == [0, 0, 0] ? [] : hunks
|
||||
|
@ -62,6 +63,16 @@ function! s:get_hunks_changes() abort
|
|||
return hunks == [0, 0, 0] ? [] : hunks
|
||||
endfunction
|
||||
|
||||
function! s:get_hunks_gitsigns() abort
|
||||
let hunks = get(b:, 'gitsigns_status', '')
|
||||
return s:parse_hunk_status(hunks)
|
||||
endfunction
|
||||
|
||||
function! s:get_hunks_coc() abort
|
||||
let hunks = get(b:, 'coc_git_status', '')
|
||||
return s:parse_hunk_status(hunks)
|
||||
endfunction
|
||||
|
||||
function! s:get_hunks_empty() abort
|
||||
return ''
|
||||
endfunction
|
||||
|
@ -76,6 +87,8 @@ function! airline#extensions#hunks#get_raw_hunks() abort
|
|||
let b:source_func = 's:get_hunks_changes'
|
||||
elseif exists('*quickfixsigns#vcsdiff#GetHunkSummary')
|
||||
let b:source_func = 'quickfixsigns#vcsdiff#GetHunkSummary'
|
||||
elseif exists(':Gitsigns')
|
||||
let b:source_func = 's:get_hunks_gitsigns'
|
||||
elseif s:coc_git_enabled()
|
||||
let b:source_func = 's:get_hunks_coc'
|
||||
else
|
||||
|
@ -97,6 +110,7 @@ function! airline#extensions#hunks#get_hunks() abort
|
|||
\ get(b:, 'source_func', '') isnot# 's:get_hunks_gitgutter' &&
|
||||
\ get(b:, 'source_func', '') isnot# 's:get_hunks_empty' &&
|
||||
\ get(b:, 'source_func', '') isnot# 's:get_hunks_changes' &&
|
||||
\ get(b:, 'source_func', '') isnot# 's:get_hunks_gitsigns' &&
|
||||
\ get(b:, 'source_func', '') isnot# 's:get_hunks_coc'
|
||||
return b:airline_hunks
|
||||
endif
|
||||
|
|
|
@ -838,6 +838,7 @@ 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>
|
||||
gitsigns.nvim <https://github.com/lewis6991/gitsigns.nvim>
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user