From 46baaf7c1e43d99e9f96563f697ea705c39eae8b Mon Sep 17 00:00:00 2001 From: ViViDboarder Date: Wed, 29 May 2024 12:08:16 -0700 Subject: [PATCH] feat(neovim): add GitHub Copilot and CopilotChat plugins This commit introduces two new plugins to the Neovim configuration: GitHub Copilot and CopilotChat. The GitHub Copilot plugin is added directly, while the CopilotChat plugin is added with a custom setup function. The setup function configures key mappings and prompts for the CopilotChat plugin. Additionally, a new global variable `install_copilot` is introduced to control the installation of these plugins. --- neovim/lua/plugins.lua | 14 +++++++++++ neovim/lua/plugins/copilotchat.lua | 40 ++++++++++++++++++++++++++++++ neovim/lua/variables.lua | 1 + 3 files changed, 55 insertions(+) create mode 100644 neovim/lua/plugins/copilotchat.lua diff --git a/neovim/lua/plugins.lua b/neovim/lua/plugins.lua index c0fd498..8dacde2 100644 --- a/neovim/lua/plugins.lua +++ b/neovim/lua/plugins.lua @@ -619,6 +619,20 @@ use({ disable = not vim.g.install_sourcegraph, }) +use({ + "https://github.com/github/copilot.vim", + disable = not vim.g.install_copilot, +}) + +use({ + "https://github.com/CopilotC-Nvim/CopilotChat.nvim", + disable = not vim.g.install_copilot, + branch = "canary", + config = function() + require("plugins.copilotchat").setup() + end, +}) + -- Auto sync after bootstrapping on a fresh box if packer_bootstrap ~= "" then packer.sync() diff --git a/neovim/lua/plugins/copilotchat.lua b/neovim/lua/plugins/copilotchat.lua new file mode 100644 index 0000000..118c917 --- /dev/null +++ b/neovim/lua/plugins/copilotchat.lua @@ -0,0 +1,40 @@ +local M = {} + +function M.setup() + require("CopilotChat").setup({ + mappings = { + complete = { + insert = "", + }, + }, + prompts = { + Explain = { + prompt = "/COPILOT_EXPLAIN Write a concise explanation for the active selection as paragraphs of text.", + }, + }, + }) + + local utils = require("utils") + if utils.try_require("telescope") ~= nil then + local cc_keymap = utils.curry_keymap("n", "cc") + + cc_keymap("h", function() + local actions = require("CopilotChat.actions") + require("CopilotChat.integrations.telescope").pick(actions.help_actions()) + end, { desc = "CopilotChat - Help" }) + + cc_keymap("p", function() + local actions = require("CopilotChat.actions") + require("CopilotChat.integrations.telescope").pick(actions.prompt_actions()) + end, { desc = "CopilotChat - Prompt" }) + + cc_keymap("c", function() + local input = vim.fn.input("Quick Chat: ") + if input ~= nil and input ~= "" then + require("CopilotChat").ask(input, { selection = require("CopilotChat.select").buffer }) + end + end, { desc = "CopilotChat - Quick Chat" }) + end +end + +return M diff --git a/neovim/lua/variables.lua b/neovim/lua/variables.lua index 55aa7b5..cacc656 100644 --- a/neovim/lua/variables.lua +++ b/neovim/lua/variables.lua @@ -1 +1,2 @@ +vim.g.install_copilot = false vim.g.install_sourcegraph = false