From adf2afae7c5752be5d1d0beb472c9967d48bf458 Mon Sep 17 00:00:00 2001 From: Christian Brabandt Date: Wed, 1 Apr 2020 10:43:11 +0200 Subject: [PATCH] hunks: still some problems with coc-git integration Fix remaining problems, test correctly for enabled coc-git plugin. --- autoload/airline/extensions.vim | 6 +++++- autoload/airline/extensions/hunks.vim | 29 +++++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/autoload/airline/extensions.vim b/autoload/airline/extensions.vim index c3b485e1..ae0fcfb9 100644 --- a/autoload/airline/extensions.vim +++ b/autoload/airline/extensions.vim @@ -211,7 +211,11 @@ function! airline#extensions#load() endif if get(g:, 'airline#extensions#hunks#enabled', 1) - \ && (exists('g:loaded_signify') || exists('g:loaded_gitgutter') || exists('g:loaded_changes') || exists('g:loaded_quickfixsigns')) + \ && (exists('g:loaded_signify') + \ || exists('g:loaded_gitgutter') + \ || exists('g:loaded_changes') + \ || exists('g:loaded_quickfixsigns') + \ || exists(':CocCommand')) call airline#extensions#hunks#init(s:ext) call add(s:loaded_ext, 'hunks') endif diff --git a/autoload/airline/extensions/hunks.vim b/autoload/airline/extensions/hunks.vim index 5f88a1ab..815efa55 100644 --- a/autoload/airline/extensions/hunks.vim +++ b/autoload/airline/extensions/hunks.vim @@ -4,13 +4,38 @@ scriptencoding utf-8 -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','')) +if !get(g:, 'loaded_signify', 0) + \ && !get(g:, 'loaded_gitgutter', 0) + \ && !get(g:, 'loaded_changes', 0) + \ && !get(g:, 'loaded_quickfixsigns', 0) + \ && !exists("*CocAction") finish endif let s:non_zero_only = get(g:, 'airline#extensions#hunks#non_zero_only', 0) let s:hunk_symbols = get(g:, 'airline#extensions#hunks#hunk_symbols', ['+', '~', '-']) +function! s:coc_git_enabled() abort + if !exists("*CocAction") + return 0 + endif + if exists("s:airline_coc_git_enabled") + return s:airline_coc_git_enabled + endif + let extensions=CocAction('extensionStats') + if type(extensions) != type([]) + " not yet initialized? Assume it is available... + return 1 + endif + let coc_git=filter(extensions, 'v:val.id is# "coc-git" && v:val.state is# "activated"') + if !empty(coc_git) + let s:airline_coc_git_enabled = 1 + else + let s:airline_coc_git_enabled = 0 + endif + return s:airline_coc_git_enabled +endfunction + function! s:get_hunks_signify() abort let hunks = sy#repo#get_stats() if hunks[0] >= 0 @@ -68,7 +93,7 @@ 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("g:coc_git_status") + elseif s:coc_git_enabled() let b:source_func = 's:get_hunks_coc' else let b:source_func = 's:get_hunks_empty'