davidsierradz / cmp-conventionalcommits

(WIP) nvim-cmp source for autocompleting git commits with conventional commits types and lerna packages as scope
MIT License
68 stars 4 forks source link

Allow to use a different filetype than "gitcommit" #5

Open Terseus opened 3 months ago

Terseus commented 3 months ago

Right now the source is hard coded to work only with the filetype gitcommit, here:

function source:is_available() return vim.bo.filetype == "gitcommit" end

This prevents to use this plugin source with other filetypes, which for example the one used by Neogit in its commit window, which is "NeogitCommitMessage".

Given that it's the user who has to configure the source using cmp.setup.filetype using nvim-cmp API I see no reason to lock it to a given filetype.

Please correct me if I'm wrong.

lemarsu commented 3 months ago

I was facing the same issue, no completion in Neogit commit buffers.

Until this is fixed, I made this very hackish workaround.

Add this to your config:

local source = require('cmp-conventionalcommits')
function source:is_available()
  return vim.list_contains({'gitcommit', 'NeogitCommitMessage'}, 'gitcommit')
end

And then, in after/ftplugin/NeogitCommitMessage.lua, copy the content of gitcommit.lua:

if vim.g.cmp_conventionalcommits_source_id ~= nil then
    require('cmp').unregister_source(vim.g.cmp_conventionalcommits_source_id)
end
vim.g.cmp_conventionalcommits_source_id = require('cmp').register_source('conventionalcommits', require('cmp-conventionalcommits').new())

It's hackish as hell, but well, it works.