1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 00:00:04 +08:00

Merge pull request #579 from SpaceVim/gitcommit_omni_2

Improve gitcommit completion
This commit is contained in:
Wang Shidong 2017-05-31 23:36:26 +08:00 committed by GitHub
commit 7febc44970
2 changed files with 26 additions and 7 deletions

View File

@ -1,17 +1,22 @@
let s:pr_kind = g:spacevim_gitcommit_pr_icon
let s:issue_kind = g:spacevim_gitcommit_issue_icon
let s: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] != ' '
while start > 0 && line[start - 1] != ' ' && line[start - 1] != '#'
let start -= 1
endwhile
if line[start - 1] == '#'
let s:complete_ol = 1
endif
return start
else
if a:base =~ '^#\d*'
return s:complete_pr()
if s:complete_ol == 1
return s:complete_pr(a:base)
endif
let res = []
for m in s:cache_commits()
@ -28,18 +33,25 @@ function! s:cache_commits() abort
return rst
endfunction
function! s:complete_pr() abort
function! s:complete_pr(base) abort
let [user,repo] = s:current_repo()
let prs = github#api#issues#List_All_for_Repo(user, repo)
if !has_key(s:cache, user . '_' . repo)
let prs = github#api#issues#List_All_for_Repo(user, repo)
let s:cache[user . '_' . repo] = prs
else
let prs = s:cache[user . '_' . repo]
endif
let rst = []
for pr in prs
let item = {
\ 'word' : '#' . pr.number,
\ 'word' : pr.number . '',
\ 'abbr' : '#' . pr.number,
\ 'menu' : pr.title,
\ 'kind' : (has_key(pr, 'pull_request') ? s:pr_kind : s:issue_kind),
\ }
call add(rst, item)
if pr.number . pr.title =~? a:base
call add(rst, item)
endif
endfor
return rst
endfunction

View File

@ -51,6 +51,13 @@ let g:deoplete#ignore_sources.php = get(g:deoplete#ignore_sources, 'php', ['phpc
"call deoplete#custom#set('phpcd', 'mark', '')
"call deoplete#custom#set('phpcd', 'input_pattern', '\w*|[^. \t]->\w*|\w*::\w*')
" gitcommit
let g:deoplete#omni#input_patterns.gitcommit = get(g:deoplete#omni#input_patterns, 'gitcommit', [
\'[ ]#[ 0-9a-zA-Z]*',
\])
let g:deoplete#ignore_sources.gitcommit = ['neosnippet']
" lua
let g:deoplete#omni_patterns.lua = get(g:deoplete#omni_patterns, 'lua', '.')