Skip to content

Commit c090747

Browse files
committed
refactor(gitcommit): simplify command setup and improve extension structure
- remove unnecessary function for creating commands - update command registration with direct vim.api.nvim_create_user_command - add type annotation for extension class - remove optional parameter from setup_commands function
1 parent 4359e47 commit c090747

File tree

1 file changed

+16
-9
lines changed
  • lua/codecompanion/_extensions/gitcommit

1 file changed

+16
-9
lines changed

lua/codecompanion/_extensions/gitcommit/init.lua

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,20 @@ When responding:
163163
end
164164
end
165165

166-
local function create_command(name, callback, desc)
167-
vim.api.nvim_create_user_command(name, callback, { desc = desc })
168-
end
169-
170-
local function setup_commands(opts)
171-
create_command("CodeCompanionGitCommit", M.generate_commit_message, "Generate Git commit message using AI")
172-
create_command("CCGitCommit", M.generate_commit_message, "Generate Git commit message using AI (short alias)")
166+
local function setup_commands()
167+
vim.api.nvim_create_user_command(
168+
"CodeCompanionGitCommit",
169+
M.generate_commit_message,
170+
{ desc = "Generate Git commit message using AI" }
171+
)
172+
vim.api.nvim_create_user_command(
173+
"CCGitCommit",
174+
M.generate_commit_message,
175+
{ desc = "Generate Git commit message using AI (short alias)" }
176+
)
173177
end
174178

179+
-- NOTE: Is this is ok??
175180
local function setup_slash_commands(opts)
176181
if not opts.add_slash_command then
177182
return
@@ -308,7 +313,9 @@ local function setup_slash_commands(opts)
308313
}
309314
end
310315

311-
return {
316+
return
317+
--- @class CodeCompanion.Extension
318+
{
312319
--- @param opts CodeCompanion.GitCommit.ExtensionOpts
313320
setup = function(opts)
314321
opts = vim.tbl_deep_extend("force", Config.default_opts, opts or {})
@@ -323,7 +330,7 @@ return {
323330
Langs.setup(opts.languages)
324331

325332
setup_tools(opts)
326-
setup_commands(opts)
333+
setup_commands()
327334
setup_slash_commands(opts)
328335
end,
329336

0 commit comments

Comments
 (0)