From a13bed2f512d4180062af050988587d445def917 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Sun, 29 Mar 2020 17:28:15 +0200 Subject: [PATCH] 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 --- CHANGELOG.md | 1 + autoload/airline/extensions/hunks.vim | 27 +++++++++++++++++++++++++-- doc/airline.txt | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 804a1ea2..ac7cafd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/autoload/airline/extensions/hunks.vim b/autoload/airline/extensions/hunks.vim index 88d03810..b1e8b155 100644 --- a/autoload/airline/extensions/hunks.vim +++ b/autoload/airline/extensions/hunks.vim @@ -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]) diff --git a/doc/airline.txt b/doc/airline.txt index 46706391..fb65c0ec 100644 --- a/doc/airline.txt +++ b/doc/airline.txt @@ -738,6 +738,7 @@ vim-gitgutter vim-signify changesPlugin quickfixsigns +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