From 5f4b67983227122bb3b4b44f4ab21b803696b277 Mon Sep 17 00:00:00 2001 From: Shidong Wang Date: Fri, 15 Oct 2021 00:19:55 +0800 Subject: [PATCH] feat(git): add omnifunc for git commit buffer --- .SpaceVim.d/ftplugin/git-commit.vim | 1 + autoload/SpaceVim/plugins/gitcommit.vim | 60 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 .SpaceVim.d/ftplugin/git-commit.vim diff --git a/.SpaceVim.d/ftplugin/git-commit.vim b/.SpaceVim.d/ftplugin/git-commit.vim new file mode 100644 index 000000000..fecb2acac --- /dev/null +++ b/.SpaceVim.d/ftplugin/git-commit.vim @@ -0,0 +1 @@ +setl omnifunc=SpaceVim#plugins#gitcommit#complete diff --git a/autoload/SpaceVim/plugins/gitcommit.vim b/autoload/SpaceVim/plugins/gitcommit.vim index 0fdf5d11e..d44a559f8 100644 --- a/autoload/SpaceVim/plugins/gitcommit.vim +++ b/autoload/SpaceVim/plugins/gitcommit.vim @@ -14,10 +14,58 @@ let s:pr_cache = {} let s:github_cache = {} +let s:commit_types = [ + \ { + \ 'word' : 'feat', + \ 'menu' : 'A new feature' + \ }, + \ { + \ 'word' : 'fix', + \ 'menu' : 'A bug fix' + \ }, + \ { + \ 'word' : 'docs', + \ 'menu' : 'Documentation only changes' + \ }, + \ { + \ 'word' : 'style', + \ 'menu' : 'Changes that do not affect the meaning of the code' + \ }, + \ { + \ 'word' : 'refactor', + \ 'menu' : 'A code change that neither fixes a bug nor adds a feature' + \ }, + \ { + \ 'word' : 'pref', + \ 'menu' : 'A code change that improves performance' + \ }, + \ { + \ 'word' : 'test', + \ 'menu' : 'Adding missing tests or correcting existing tests' + \ }, + \ { + \ 'word' : 'build', + \ 'menu' : 'Changes that affect the build system or external dependencies' + \ }, + \ { + \ 'word' : 'ci', + \ 'menu' : 'Changes to our CI configuration files and scripts' + \ }, + \ { + \ 'word' : 'chore', + \ 'menu' : 'Other changes that do not modify src or test files' + \ }, + \ { + \ 'word' : 'revert', + \ 'menu' : 'Reverts a previous commit' + \ }, + \ ] + function! SpaceVim#plugins#gitcommit#complete(findstart, base) abort if a:findstart let s:complete_ol = 0 + let s:complete_type = 0 let line = getline('.') let start = col('.') - 1 while start > 0 && line[start - 1] !=# ' ' && line[start - 1] !=# '#' @@ -25,11 +73,15 @@ function! SpaceVim#plugins#gitcommit#complete(findstart, base) abort endwhile if line[start - 1] ==# '#' let s:complete_ol = 1 + elseif line('.') ==# 1 && start ==# 0 + let s:complete_type = 1 endif return start else if s:complete_ol == 1 return s:complete_pr(a:base) + elseif s:complete_type == 1 + return s:complete('types') endif let res = [] for m in s:cache_commits() @@ -46,6 +98,14 @@ function! s:cache_commits() abort return rst endfunction +function! s:complete(what) abort + if a:what ==# 'types' + return s:commit_types + else + return [] + endif +endfunction + function! s:complete_pr(base) abort let [user,repo] = s:current_repo() let s:user = user