Add codecompanion for interactive ai help

This commit is contained in:
salomaestro
2025-01-28 13:19:06 +01:00
parent baf14d1b8e
commit 1bb24a69fc
4 changed files with 93 additions and 13 deletions

View File

@@ -6,7 +6,7 @@
local M = {} local M = {}
M.base46 = { M.base46 = {
theme = "github_dark", theme = "monekai",
-- hl_override = { -- hl_override = {
-- Comment = { italic = true }, -- Comment = { italic = true },

View File

@@ -0,0 +1,54 @@
local cc = require "codecompanion"
cc.setup {
adapters = {
llama3 = function()
return require("codecompanion.adapters").extend("ollama", {
name = "llama3",
schema = {
model = {
default = "llama3.1:latest",
},
},
})
end,
mistral = function()
return require("codecompanion.adapters").extend("ollama", {
name = "mistral",
schema = {
model = {
default = "mistral:latest",
},
},
})
end,
qwen = function()
return require("codecompanion.adapters").extend("ollama", {
name = "qwen",
schema = {
model = {
default = "qwen2.5-coder",
},
},
})
end,
},
strategies = {
chat = {
adapter = "copilot",
},
inline = {
adapter = "copilot",
},
},
display = {
-- diff = {
-- provider = "mini_diff",
-- },
action_palette = {
provider = "mini_pick",
},
},
opts = {
log_level = "DEBUG",
},
}

View File

@@ -10,10 +10,6 @@ local diag = vim.diagnostic
map("n", ";", ":", { desc = "CMD enter command mode" }) map("n", ";", ":", { desc = "CMD enter command mode" })
map("i", "jk", "<ESC>") map("i", "jk", "<ESC>")
-- map({ "n", "i", "v" }, "<C-s>", "<cmd> w <cr>")
map("n", "<leader>cp", "<cmd> Copilot panel<cr>", { desc = "Copilot panel" })
map("n", "<leader>ca", function() map("n", "<leader>ca", function()
vim.lsp.buf.code_action() vim.lsp.buf.code_action()
end, { desc = "LSP code action" }) end, { desc = "LSP code action" })
@@ -129,3 +125,17 @@ end, { desc = "Frames" })
map("n", "<Leader>ds", function() map("n", "<Leader>ds", function()
widgets.centered_float(widgets.scopes) widgets.centered_float(widgets.scopes)
end, { desc = "Scopes" }) end, { desc = "Scopes" })
-- CodeCompletion mappings
map({ "n", "v" }, "<C-a>", "<cmd>CodeCompanionActions<cr>", { noremap = true, silent = true, desc = "Code Actions" })
map({ "n", "v" }, "<Leader>a", "<cmd>CodeCompanionChat Toggle<cr>", { noremap = true, silent = true, desc = "Code Chat" })
map("v", "ga", "<cmd>CodeCompanionChat Add<cr>", { noremap = true, silent = true, desc = "Code Chat Add Visual" })
map("v", "<Leader>ce", function()
require("codecompanion").prompt("explain")
end, { noremap = true, silent = true, desc = "Explain Selection" }
)
-- Expand 'cc' into 'CodeCompanion' in the command line
vim.cmd([[cab cc CodeCompanion]])

View File

@@ -113,19 +113,14 @@ return {
}, },
{ {
{ "folke/persistence.nvim",
"folke/persistence.nvim", event = "BufReadPre", -- this will only start session saving when an actual file was opened
event = "BufReadPre", -- this will only start session saving when an actual file was opened
opts = {
-- add any custom options here
},
},
}, },
{ {
"NvChad/nvcommunity", "NvChad/nvcommunity",
{ import = "nvcommunity.git.diffview" }, { import = "nvcommunity.git.diffview" },
{ import = "nvcommunity.git.lazygit" }, -- { import = "nvcommunity.git.lazygit" },
{ import = "nvcommunity.completion.copilot" }, { import = "nvcommunity.completion.copilot" },
{ {
"copilot.lua", "copilot.lua",
@@ -195,6 +190,27 @@ return {
lazy = false, lazy = false,
}, },
{
"echasnovski/mini.nvim",
version = "*",
config = function()
require("mini.diff").setup()
require("mini.pick").setup()
end,
},
{
"olimorris/codecompanion.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
config = function()
require "configs.codecompanion"
end,
lazy = false,
},
-- Install a plugin -- Install a plugin
{ {
"max397574/better-escape.nvim", "max397574/better-escape.nvim",