From d2c8f806f7cd4665507604ce4a5886e91a80485d Mon Sep 17 00:00:00 2001 From: Georgi Dimitrov Date: Thu, 15 Feb 2024 00:23:50 +0000 Subject: [PATCH] neovim: add custom gitcommit completion source --- nvim/lua/plugins/autocompletion.lua | 2 + nvim/lua/user/cmp-nvim/gitcommit.lua | 63 ++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 nvim/lua/user/cmp-nvim/gitcommit.lua diff --git a/nvim/lua/plugins/autocompletion.lua b/nvim/lua/plugins/autocompletion.lua index 28b6ed85..bd2942bf 100644 --- a/nvim/lua/plugins/autocompletion.lua +++ b/nvim/lua/plugins/autocompletion.lua @@ -160,9 +160,11 @@ return { }, }) + require('user.cmp-nvim.gitcommit') cmp.setup.filetype('gitcommit', { sources = cmp.config.sources({ { name = 'git' }, + { name = 'gitcommit' }, }, { { name = 'buffer' }, }), diff --git a/nvim/lua/user/cmp-nvim/gitcommit.lua b/nvim/lua/user/cmp-nvim/gitcommit.lua new file mode 100644 index 00000000..8f9a9196 --- /dev/null +++ b/nvim/lua/user/cmp-nvim/gitcommit.lua @@ -0,0 +1,63 @@ +local cc = { + { + label = 'build', + documentation = 'Changes that affect the build system or external dependencies', + }, + { + label = 'chore', + documentation = 'Other changes that dont modify src or test files', + }, + { + label = 'ci', + documentation = 'Changes to our CI configuration files and scripts', + }, + { + label = 'docs', + documentation = 'Documentation only changes', + }, + { + label = 'feat', + documentation = 'A new feature', + }, + { + label = 'fix', + documentation = 'A bug fix', + }, + { + label = 'perf', + documentation = 'A code change that improves performance', + }, + { + label = 'refactor', + documentation = 'A code change that neither fixes a bug nor adds a feature', + }, + { + label = 'style', + documentation = 'Changes that do not affect the meaning of the code', + }, + { + label = 'test', + documentation = 'Adding missing tests or correcting existing tests', + }, +} + +local items = {} +for k, v in ipairs(cc) do + items[k] = { + label = v.label, + kind = require('cmp').lsp.CompletionItemKind.Keyword, + documentation = v.documentation, + } +end + +local source = {} + +function source:is_available() + return vim.bo.filetype == 'gitcommit' +end + +function source:complete(request, callback) + callback(items) +end + +require('cmp').register_source('gitcommit', source)