Skip to content

Commit

Permalink
neovim: add custom gitcommit completion source
Browse files Browse the repository at this point in the history
  • Loading branch information
geodimm committed Feb 15, 2024
1 parent 97cdb86 commit d2c8f80
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
2 changes: 2 additions & 0 deletions nvim/lua/plugins/autocompletion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,11 @@ return {
},
})

require('user.cmp-nvim.gitcommit')
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'git' },
{ name = 'gitcommit' },
}, {
{ name = 'buffer' },
}),
Expand Down
63 changes: 63 additions & 0 deletions nvim/lua/user/cmp-nvim/gitcommit.lua
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit d2c8f80

Please sign in to comment.