Skip to content

Commit 640f361

Browse files
committed
feat: add CCExplain command
1 parent bc6b743 commit 640f361

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lua/CopilotChat/init.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
-- Define a module table
1+
local utils = require('CopilotChat.utils')
2+
23
local M = {}
34

45
-- Set up the plugin
56
M.setup = function()
6-
vim.notify(
7-
"Please run ':UpdateRemotePlugins' and restart Neovim to use CopilotChat.nvim",
8-
vim.log.levels.INFO,
9-
{
10-
title = 'CopilotChat.nvim',
11-
}
12-
)
7+
-- Add new command to explain the selected text with CopilotChat
8+
utils.create_cmd('CChatExplain', function(opts)
9+
vim.cmd('CChat Explain how it works')
10+
end, { nargs = '*', range = true })
1311
end
1412

1513
return M

lua/CopilotChat/utils.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
local M = {}
2+
3+
--- Create custom command
4+
---@param cmd string The command name
5+
---@param func function The function to execute
6+
---@param opt table The options
7+
M.create_cmd = function(cmd, func, opt)
8+
opt = vim.tbl_extend('force', { desc = 'CopilotChat.nvim ' .. cmd }, opt or {})
9+
vim.api.nvim_create_user_command(cmd, func, opt)
10+
end
11+
12+
return M

0 commit comments

Comments
 (0)