From 0db6d4183be82d6193c07a589db2638ef983bbac Mon Sep 17 00:00:00 2001 From: Martin Larsson Date: Tue, 22 Apr 2025 15:29:49 +0200 Subject: [PATCH] Update code companion to use copilot claude sonnet 3.7, add support for gemini and openai with api keys. Additionally add code companion. Finally, add VectorCode with Code Companion which caches and gives context of private local projects to AI for better insight. completion in blink. --- nvim/lazy-lock.json | 4 +- nvim/lua/plugs/blink.lua | 5 +- nvim/lua/plugs/codecompanion.lua | 98 ++++++++++++++++++++++++++++---- 3 files changed, 93 insertions(+), 14 deletions(-) diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json index 72cba92..230e637 100644 --- a/nvim/lazy-lock.json +++ b/nvim/lazy-lock.json @@ -1,4 +1,5 @@ { + "VectorCode": { "branch": "main", "commit": "caac1c8d040118c50740ab94ffbe3a4d52db583d" }, "arrow.nvim": { "branch": "master", "commit": "6e0f726f55f99332dd726a53effd6813786b6d49" }, "blink.cmp": { "branch": "main", "commit": "cb5e346d9e0efa7a3eee7fd4da0b690c48d2a98e" }, "codecompanion.nvim": { "branch": "main", "commit": "35b11dc4b292519a5c09fb2c0c0e8a8832e9e821" }, @@ -12,6 +13,7 @@ "lspsaga.nvim": { "branch": "main", "commit": "501265c9b30b191ab5e5a66d104e72fb155cf3be" }, "lualine.nvim": { "branch": "master", "commit": "0ea56f91b7f51a37b749c050a5e5dfdd56b302b3" }, "markview.nvim": { "branch": "main", "commit": "4f9ad36efe01c283aa886453ba75bf569c897c84" }, + "mini.diff": { "branch": "main", "commit": "7e268d0241255abaa07b8aa0ddff028f7315fe21" }, "neogit": { "branch": "master", "commit": "97f83f1dc51dee41e08e3c7a8adf00e1083e3178" }, "neovim-ayu": { "branch": "master", "commit": "f5da37a8ddd62fc3a7b28900c4d1b807a3582584" }, "noice.nvim": { "branch": "main", "commit": "0427460c2d7f673ad60eb02b35f5e9926cf67c59" }, @@ -26,7 +28,7 @@ "nvim-nio": { "branch": "master", "commit": "21f5324bfac14e22ba26553caf69ec76ae8a7662" }, "nvim-surround": { "branch": "main", "commit": "caf6f633d4d77a29b6e265b560c5a035d171a913" }, "nvim-treesitter": { "branch": "master", "commit": "0e21ee8df6235511c02bab4a5b391d18e165a58d" }, - "nvim-treesitter-context": { "branch": "master", "commit": "439789a9a8df9639ecd749bb3286b77117024a6f" }, + "nvim-treesitter-context": { "branch": "master", "commit": "d0dd7ce5a9d0be1f28086e818e52fdc5c78975df" }, "nvim-treesitter-textobjects": { "branch": "master", "commit": "698b5f805722254bca3c509591c1806d268b6c2f" }, "nvim-web-devicons": { "branch": "master", "commit": "57dfa947cc88cdf1baa2c7e13ed31edddd8fb1d1" }, "persistence.nvim": { "branch": "main", "commit": "166a79a55bfa7a4db3e26fc031b4d92af71d0b51" }, diff --git a/nvim/lua/plugs/blink.lua b/nvim/lua/plugs/blink.lua index 7b63e56..512863f 100644 --- a/nvim/lua/plugs/blink.lua +++ b/nvim/lua/plugs/blink.lua @@ -16,7 +16,10 @@ return { -- Default list of enabled providers defined so that you can extend it -- elsewhere in your config, without redefining it, due to `opts_extend` sources = { - default = { "lsp", "path", "snippets", "buffer" }, + default = { "lsp", "path", "snippets", "buffer", }, + per_filetype = { + codecompanion = { "codecompanion", }, + }, }, -- (Default) Rust fuzzy matcher for typo resistance and significantly better performance diff --git a/nvim/lua/plugs/codecompanion.lua b/nvim/lua/plugs/codecompanion.lua index 8966ae2..ba20fc0 100644 --- a/nvim/lua/plugs/codecompanion.lua +++ b/nvim/lua/plugs/codecompanion.lua @@ -1,25 +1,98 @@ return { - "olimorris/codecompanion.nvim", + "olimorris/codecompanion.nvim", -- The KING of AI programming dependencies = { - "nvim-lua/plenary.nvim", - "nvim-treesitter/nvim-treesitter", + { + "Davidyz/VectorCode", + version = "*", + build = "pipx upgrade vectorcode", + dependencies = { "nvim-lua/plenary.nvim" }, + }, + "echasnovski/mini.diff", }, opts = { + adapters = { + copilot = function() + return require("codecompanion.adapters").extend("copilot", { + schema = { + model = { + default = "claude-3.7-sonnet", + }, + }, + }) + end, + gemini = function() + return require("codecompanion.adapters").extend("gemini", { + schema = { + model = { + default = "gemini-2.5-pro-exp-03-25", + }, + }, + }) + end, + openai = function() + return require("codecompanion.adapters").extend("openai", { + opts = { + stream = true, + }, + schema = { + model = { + default = function() + return "gpt-4o" + end, + }, + }, + }) + end, + }, strategies = { chat = { adapter = "copilot", + roles = { + user = "Martin", + }, + keymaps = { + send = { + modes = { + i = { "", "" }, + }, + }, + completion = { + modes = { + i = "", + }, + }, + }, + slash_commands = { + ["buffer"] = { + opts = { + keymaps = { + modes = { + i = "", + }, + }, + }, + }, + ["help"] = { + opts = { + max_lines = 1000, + }, + }, + }, + tools = { + vectorcode = { + description = "Run VectorCode to retrieve the project context.", + callback = function() + return require("vectorcode.integrations").codecompanion.chat.make_tool() + end, + }, + }, }, - inline = { - adapter = "copilot", - }, - agent = { - adapter = "copilot", - }, - }, - adapters = { - copilot = function() return require("codecompanion.adapters").extend("copilot", {}) end, + inline = { adapter = "copilot" }, }, display = { + action_palette = { + provider = "default", + }, diff = { provider = "mini_diff", }, @@ -29,6 +102,7 @@ return { }, }, keys = { + { "", "CodeCompanionActions" }, { "ci", "CodeCompanion" }, { "cc", "CodeCompanionChat toggle" }, { "ce", "CodeCompanion /explain", mode = "v" },