From ca0ef50614d950275333913edce2ad4af38e44b2 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Thu, 12 Apr 2018 23:04:47 +0800 Subject: [PATCH] Fixup (#1624) * Implement async gitcommit * Fix prs --- autoload/SpaceVim/plugins/gitcommit.vim | 35 +++++++++++++++++-------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/autoload/SpaceVim/plugins/gitcommit.vim b/autoload/SpaceVim/plugins/gitcommit.vim index 0ba8fb30c..a1cbc1bd2 100644 --- a/autoload/SpaceVim/plugins/gitcommit.vim +++ b/autoload/SpaceVim/plugins/gitcommit.vim @@ -1,22 +1,29 @@ +"============================================================================= +" gitcommit.vim --- omni plugin for git commit +" Copyright (c) 2016-2017 Wang Shidong & Contributors +" Author: Wang Shidong < wsdjeg at 163.com > +" URL: https://spacevim.org +" License: GPLv3 +"============================================================================= + + let s:pr_kind = g:spacevim_gitcommit_pr_icon let s:issue_kind = g:spacevim_gitcommit_issue_icon let s:cache = {} let s:pr_cache = {} -" pr_cache -" { -" 'user - repo' : { pr.number : pr} -" } -" TODO: add asycn support +let s:github_cache = {} + + function! SpaceVim#plugins#gitcommit#complete(findstart, base) abort if a:findstart let s:complete_ol = 0 let line = getline('.') let start = col('.') - 1 - while start > 0 && line[start - 1] != ' ' && line[start - 1] != '#' + while start > 0 && line[start - 1] !=# ' ' && line[start - 1] !=# '#' let start -= 1 endwhile - if line[start - 1] == '#' + if line[start - 1] ==# '#' let s:complete_ol = 1 endif return start @@ -41,12 +48,14 @@ endfunction function! s:complete_pr(base) abort let [user,repo] = s:current_repo() - if !has_key(s:cache, user . '_' . repo) + let s:user = user + let s:repo = repo + if !has_key(s:pr_cache, user . '_' . repo) call s:cache_prs(user, repo) endif - let prs = get(s:cache, user . '_' . repo, []) + let prs = get(s:pr_cache, user . '_' . repo, {}) let rst = [] - for pr in prs + for pr in values(prs) let item = { \ 'word' : pr.number . '', \ 'abbr' : '#' . pr.number, @@ -93,7 +102,11 @@ function! s:cache_prs(user, repo) abort if !has_key(s:pr_cache, a:user . '_' . a:repo) call extend(s:pr_cache, {a:user . '_' . a:repo : {}}) endif - call github#api#issue#list_all_for_repo(a:user, a:repo, function('s:list_callback')) + call github#api#issues#async_list_opened(a:user, a:repo, function('s:callback')) +endfunction + +function! s:callback(data) abort + call s:list_callback(s:user, s:repo, a:data) endfunction " data is a list a PRs in one page