1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-12 09:35:40 +08:00
* Implement async gitcommit

* Fix prs
This commit is contained in:
Wang Shidong 2018-04-12 23:04:47 +08:00 committed by GitHub
parent 1e5ba2553d
commit ca0ef50614
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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:pr_kind = g:spacevim_gitcommit_pr_icon
let s:issue_kind = g:spacevim_gitcommit_issue_icon let s:issue_kind = g:spacevim_gitcommit_issue_icon
let s:cache = {} let s:cache = {}
let s:pr_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 function! SpaceVim#plugins#gitcommit#complete(findstart, base) abort
if a:findstart if a:findstart
let s:complete_ol = 0 let s:complete_ol = 0
let line = getline('.') let line = getline('.')
let start = col('.') - 1 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 let start -= 1
endwhile endwhile
if line[start - 1] == '#' if line[start - 1] ==# '#'
let s:complete_ol = 1 let s:complete_ol = 1
endif endif
return start return start
@ -41,12 +48,14 @@ endfunction
function! s:complete_pr(base) abort function! s:complete_pr(base) abort
let [user,repo] = s:current_repo() 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) call s:cache_prs(user, repo)
endif endif
let prs = get(s:cache, user . '_' . repo, []) let prs = get(s:pr_cache, user . '_' . repo, {})
let rst = [] let rst = []
for pr in prs for pr in values(prs)
let item = { let item = {
\ 'word' : pr.number . '', \ 'word' : pr.number . '',
\ 'abbr' : '#' . 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) if !has_key(s:pr_cache, a:user . '_' . a:repo)
call extend(s:pr_cache, {a:user . '_' . a:repo : {}}) call extend(s:pr_cache, {a:user . '_' . a:repo : {}})
endif 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 endfunction
" data is a list a PRs in one page " data is a list a PRs in one page