From 3472e86e6a6f3e7bf2341d02e974908da564d932 Mon Sep 17 00:00:00 2001 From: Carlos Date: Sun, 11 May 2025 11:29:47 -0400 Subject: [PATCH] feat adding copilot --- lua/cargdev/plugins/aicargdev.lua | 2 +- lua/cargdev/plugins/copilot.lua | 110 ++++++++++++++++++++---------- 2 files changed, 76 insertions(+), 36 deletions(-) diff --git a/lua/cargdev/plugins/aicargdev.lua b/lua/cargdev/plugins/aicargdev.lua index 4937c2d..554e40d 100644 --- a/lua/cargdev/plugins/aicargdev.lua +++ b/lua/cargdev/plugins/aicargdev.lua @@ -9,7 +9,7 @@ return { vendors = { cargdev = { name = "cargdev", -- Optional - endpoint = "https://api-ai.cargdev.io/api/generate", + endpoint = "https://api-ai.cargdev.io/api/generate", -- API endpoint api_key_name = "CARGDEV_API_KEY", -- reference the ENV VAR below model = "codellama:7b", __inherited_from = "ollama", -- ensures compatibility diff --git a/lua/cargdev/plugins/copilot.lua b/lua/cargdev/plugins/copilot.lua index 499360c..08a2780 100644 --- a/lua/cargdev/plugins/copilot.lua +++ b/lua/cargdev/plugins/copilot.lua @@ -1,41 +1,81 @@ return { - "zbirenbaum/copilot.lua", - lazy = false, -- Load at startup - enabled = true, - config = function() - require("copilot").setup({ - panel = { + { + -- Main Copilot plugin + "zbirenbaum/copilot.lua", + lazy = false, -- Load at startup + enabled = true, + config = function() + require("copilot").setup({ + panel = { + enabled = true, + auto_refresh = false, + keymap = { + jump_prev = "[[", + jump_next = "]]", + accept = "", + refresh = "gr", + open = "", + }, + layout = { + position = "bottom", -- | top | left | right | horizontal | vertical + ratio = 0.4, + }, + }, + suggestion = { + enabled = true, + auto_trigger = true, + debounce = 75, + trigger_on_accept = true, + keymap = { + accept = "", -- Accept suggestion + next = "", -- Next suggestion + prev = "", -- Previous suggestion + dismiss = "", -- Dismiss suggestion + }, + }, + filetypes = { + markdown = true, + ["*"] = true, -- Enable for all filetypes + }, + copilot_node_command = "node", -- Ensure your system's Node.js is v20+ + }) + end, + }, + { + -- Copilot Chat plugin + "CopilotC-Nvim/CopilotChat.nvim", + dependencies = { + { "github/copilot.vim" }, -- Or zbirenbaum/copilot.lua + { "nvim-lua/plenary.nvim", branch = "master" }, -- For curl, log and async functions + }, + build = "make tiktoken", -- Only on MacOS or Linux + opts = { + layout = { + position = "right", -- Position of the chat window + ratio = 0.5, + }, + floating = { enabled = true, - auto_refresh = false, - keymap = { - jump_prev = "[[", - jump_next = "]]", - accept = "", - refresh = "gr", - open = "", - }, - layout = { - position = "bottom", -- | top | left | right | horizontal | vertical - ratio = 0.4, + border = "rounded", + }, + prompts = { + Rename = { + prompt = "Please rename the variable correctly in given selection based on context", + selection = function(source) + local select = require("CopilotChat.select") + return select.visual(source) + end, }, }, - suggestion = { - enabled = true, - auto_trigger = true, - debounce = 75, - trigger_on_accept = true, - keymap = { - accept = "", -- Accept suggestion - next = "", -- Next suggestion - prev = "", -- Previous suggestion - dismiss = "", -- Dismiss suggestion - }, + keys = { + { "zn", ":CopilotChatRename", mode = "v", desc = "Rename the variable" }, + { "zc", ":CopilotChat", mode = "n", desc = "Chat with Copilot" }, + { "ze", ":CopilotChatExplain", mode = "v", desc = "Explain Code" }, + { "zr", ":CopilotChatReview", mode = "v", desc = "Review Code" }, + { "zf", ":CopilotChatFix", mode = "v", desc = "Fix Code Issues" }, + { "zo", ":CopilotChatOptimize", mode = "v", desc = "Optimize Code" }, + { "zd", ":CopilotChatDocs", mode = "v", desc = "Generate Docs" }, }, - filetypes = { - markdown = true, - ["*"] = true, -- Enable for all filetypes - }, - copilot_node_command = "node", -- Ensure your system's Node.js is v20+ - }) - end, + }, + }, }