Skip to content

Commit

Permalink
feat: add CCExplain command
Browse files Browse the repository at this point in the history
  • Loading branch information
jellydn committed Dec 23, 2023
1 parent bc6b743 commit 640f361
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
-- Define a module table
local utils = require('CopilotChat.utils')

local M = {}

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

return M
12 changes: 12 additions & 0 deletions lua/CopilotChat/utils.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
local M = {}

--- Create custom command
---@param cmd string The command name
---@param func function The function to execute
---@param opt table The options
M.create_cmd = function(cmd, func, opt)
opt = vim.tbl_extend('force', { desc = 'CopilotChat.nvim ' .. cmd }, opt or {})
vim.api.nvim_create_user_command(cmd, func, opt)
end

return M

0 comments on commit 640f361

Please sign in to comment.