updates for codecompanion

This commit is contained in:
2026-01-05 09:03:33 -06:00
parent a62c3731f9
commit 5e9ec0722c
3 changed files with 146 additions and 142 deletions

View File

@@ -8,7 +8,11 @@ return {
-- For progress notifications -- For progress notifications
"j-hui/fidget.nvim", "j-hui/fidget.nvim",
-- For statusline integration -- For statusline integration
"nvim-lualine/lualine.nvim", -- "nvim-lualine/lualine.nvim",
{
"franco-ruggeri/codecompanion-lualine.nvim", -- Add this line
dependencies = { "olimorris/codecompanion.nvim" },
},
}, },
event = "VeryLazy", -- Lazy load the plugin event = "VeryLazy", -- Lazy load the plugin
config = function() config = function()
@@ -90,7 +94,6 @@ return {
{ noremap = true, silent = true, desc = "Show current CodeCompanion model" } { noremap = true, silent = true, desc = "Show current CodeCompanion model" }
) )
-- Create commands to show and change current model -- Create commands to show and change current model
vim.api.nvim_create_user_command("CodeCompanionModel", function() vim.api.nvim_create_user_command("CodeCompanionModel", function()
local ok, codecompanion = pcall(require, "codecompanion") local ok, codecompanion = pcall(require, "codecompanion")
@@ -111,7 +114,7 @@ return {
vim.notify(string.format("Current CodeCompanion model: %s", model_info), vim.log.levels.INFO) vim.notify(string.format("Current CodeCompanion model: %s", model_info), vim.log.levels.INFO)
end, { end, {
desc = "Show current CodeCompanion model" desc = "Show current CodeCompanion model",
}) })
vim.api.nvim_create_user_command("CodeCompanionSwitchModel", function(args) vim.api.nvim_create_user_command("CodeCompanionSwitchModel", function(args)
@@ -123,7 +126,7 @@ return {
local adapter_map = { local adapter_map = {
sonnet = "anthropic", sonnet = "anthropic",
opus = "anthropic_opus" opus = "anthropic_opus",
} }
local adapter = adapter_map[model:lower()] local adapter = adapter_map[model:lower()]
@@ -139,13 +142,13 @@ return {
vim.notify(string.format("Switched to %s model", model), vim.log.levels.INFO) vim.notify(string.format("Switched to %s model", model), vim.log.levels.INFO)
-- Refresh lualine to update the status -- Refresh lualine to update the status
pcall(require("lualine").refresh) -- pcall(require("lualine").refresh)
end, { end, {
nargs = 1, nargs = 1,
complete = function() complete = function()
return {"sonnet", "opus"} return { "sonnet", "opus" }
end, end,
desc = "Switch CodeCompanion model (sonnet/opus)" desc = "Switch CodeCompanion model (sonnet/opus)",
}) })
-- Additional keymaps for Opus -- Additional keymaps for Opus

View File

@@ -13,7 +13,7 @@ return {
end, end,
}) })
-- load the colorscheme here -- load the colorscheme here
-- vim.cmd([[colorscheme catppuccin]]) vim.cmd([[colorscheme catppuccin]])
end, end,
}, },
{ {
@@ -53,7 +53,7 @@ return {
end, end,
}) })
-- load the colorscheme here -- load the colorscheme here
vim.cmd([[colorscheme tokyonight]]) -- vim.cmd([[colorscheme tokyonight]])
-- Sets colors to line numbers Above, Current and Below in this order -- Sets colors to line numbers Above, Current and Below in this order
function LineNumberColors() function LineNumberColors()
vim.api.nvim_set_hl(0, "LineNrAbove", { fg = "#51B3EC", bg = "#495060", bold = true }) vim.api.nvim_set_hl(0, "LineNrAbove", { fg = "#51B3EC", bg = "#495060", bold = true })

View File

@@ -10,131 +10,131 @@ return {
-- Short mode names (single letters) -- Short mode names (single letters)
local short_mode_map = { local short_mode_map = {
['n'] = 'N', ["n"] = "N",
['no'] = 'N', ["no"] = "N",
['nov'] = 'N', ["nov"] = "N",
['noV'] = 'N', ["noV"] = "N",
['niI'] = 'N', ["niI"] = "N",
['niR'] = 'N', ["niR"] = "N",
['niV'] = 'N', ["niV"] = "N",
['i'] = 'I', ["i"] = "I",
['ic'] = 'I', ["ic"] = "I",
['ix'] = 'I', ["ix"] = "I",
['v'] = 'V', ["v"] = "V",
['V'] = 'VL', ["V"] = "VL",
[''] = 'VB', [""] = "VB",
['s'] = 'S', ["s"] = "S",
['S'] = 'SL', ["S"] = "SL",
[''] = 'SB', [""] = "SB",
['r'] = 'R', ["r"] = "R",
['rm'] = 'R', ["rm"] = "R",
['r?'] = 'R', ["r?"] = "R",
['R'] = 'R', ["R"] = "R",
['Rv'] = 'R', ["Rv"] = "R",
['c'] = 'C', ["c"] = "C",
['cv'] = 'C', ["cv"] = "C",
['ce'] = 'C', ["ce"] = "C",
['t'] = 'T', ["t"] = "T",
} }
-- Full mode names -- Full mode names
local full_mode_map = { local full_mode_map = {
['n'] = 'NORMAL', ["n"] = "NORMAL",
['no'] = 'NORMAL', ["no"] = "NORMAL",
['nov'] = 'NORMAL', ["nov"] = "NORMAL",
['noV'] = 'NORMAL', ["noV"] = "NORMAL",
['niI'] = 'NORMAL', ["niI"] = "NORMAL",
['niR'] = 'NORMAL', ["niR"] = "NORMAL",
['niV'] = 'NORMAL', ["niV"] = "NORMAL",
['i'] = 'INSERT', ["i"] = "INSERT",
['ic'] = 'INSERT', ["ic"] = "INSERT",
['ix'] = 'INSERT', ["ix"] = "INSERT",
['v'] = 'VISUAL', ["v"] = "VISUAL",
['V'] = 'V-LINE', ["V"] = "V-LINE",
[''] = 'V-BLOCK', [""] = "V-BLOCK",
['s'] = 'SELECT', ["s"] = "SELECT",
['S'] = 'S-LINE', ["S"] = "S-LINE",
[''] = 'S-BLOCK', [""] = "S-BLOCK",
['r'] = 'REPLACE', ["r"] = "REPLACE",
['rm'] = 'REPLACE', ["rm"] = "REPLACE",
['r?'] = 'REPLACE', ["r?"] = "REPLACE",
['R'] = 'REPLACE', ["R"] = "REPLACE",
['Rv'] = 'REPLACE', ["Rv"] = "REPLACE",
['c'] = 'COMMAND', ["c"] = "COMMAND",
['cv'] = 'COMMAND', ["cv"] = "COMMAND",
['ce'] = 'COMMAND', ["ce"] = "COMMAND",
['t'] = 'TERMINAL', ["t"] = "TERMINAL",
} }
-- Enhanced CodeCompanion status function with model display -- Enhanced CodeCompanion status function with model display
local function codecompanion_status() -- local function codecompanion_status()
local ok, codecompanion = pcall(require, "codecompanion") -- local ok, codecompanion = pcall(require, "codecompanion")
if not ok then -- if not ok then
return "" -- return ""
end -- end
--
-- Get current adapter and model info -- -- Get current adapter and model info
local current_adapter = nil -- local current_adapter = nil
local current_model = nil -- local current_model = nil
--
-- Try to get adapter from active chat buffer -- -- Try to get adapter from active chat buffer
local chat_ok, chat = pcall(codecompanion.buf_get_chat) -- local chat_ok, chat = pcall(codecompanion.buf_get_chat)
if chat_ok and chat and chat.adapter then -- if chat_ok and chat and chat.adapter then
current_adapter = chat.adapter.name or chat.adapter -- current_adapter = chat.adapter.name or chat.adapter
current_model = chat.adapter.schema and chat.adapter.schema.model and chat.adapter.schema.model.default -- current_model = chat.adapter.schema and chat.adapter.schema.model and chat.adapter.schema.model.default
end -- end
--
-- If no active chat, get default adapter from config -- -- If no active chat, get default adapter from config
if not current_adapter then -- if not current_adapter then
local config_ok, config = pcall(function() -- local config_ok, config = pcall(function()
return codecompanion.config.strategies.chat.adapter -- return codecompanion.config.strategies.chat.adapter
end) -- end)
if config_ok and config then -- if config_ok and config then
current_adapter = config -- current_adapter = config
-- Try to get model from adapter config -- -- Try to get model from adapter config
local adapter_config_ok, adapter_config = pcall(function() -- local adapter_config_ok, adapter_config = pcall(function()
return codecompanion.config.adapters.http[config] -- return codecompanion.config.adapters.http[config]
end) -- end)
if adapter_config_ok and type(adapter_config) == "function" then -- if adapter_config_ok and type(adapter_config) == "function" then
local adapter_instance_ok, adapter_instance = pcall(adapter_config) -- local adapter_instance_ok, adapter_instance = pcall(adapter_config)
if adapter_instance_ok and adapter_instance.schema and adapter_instance.schema.model then -- if adapter_instance_ok and adapter_instance.schema and adapter_instance.schema.model then
current_model = adapter_instance.schema.model.default -- current_model = adapter_instance.schema.model.default
end -- end
end -- end
end -- end
end -- end
--
-- Format the display string -- -- Format the display string
local status_parts = {} -- local status_parts = {}
--
-- Check for active requests/chats first -- -- Check for active requests/chats first
local status = codecompanion.status() -- local status = codecompanion.status()
if status and status ~= "" then -- if status and status ~= "" then
table.insert(status_parts, "🤖") -- table.insert(status_parts, "🤖")
elseif chat_ok and chat then -- elseif chat_ok and chat then
table.insert(status_parts, "💬") -- table.insert(status_parts, "💬")
end -- end
--
-- Add model info -- -- Add model info
if current_model then -- if current_model then
-- Shorten model names for better display -- -- Shorten model names for better display
local short_model = current_model -- local short_model = current_model
:gsub("claude%-sonnet%-4%-20250514", "Sonnet") -- :gsub("claude%-sonnet%-4%-20250514", "Sonnet")
:gsub("claude%-opus%-4%-5%-20251101", "Opus") -- :gsub("claude%-opus%-4%-5%-20251101", "Opus")
:gsub("claude%-3%-5%-sonnet%-20241022", "3.5S") -- :gsub("claude%-3%-5%-sonnet%-20241022", "3.5S")
:gsub("claude%-3%-haiku%-20240307", "Haiku") -- :gsub("claude%-3%-haiku%-20240307", "Haiku")
:gsub("gpt%-4o", "GPT-4o") -- :gsub("gpt%-4o", "GPT-4o")
:gsub("gpt%-4", "GPT-4") -- :gsub("gpt%-4", "GPT-4")
:gsub("gpt%-3.5%-turbo", "GPT-3.5") -- :gsub("gpt%-3.5%-turbo", "GPT-3.5")
table.insert(status_parts, short_model) -- table.insert(status_parts, short_model)
elseif current_adapter then -- elseif current_adapter then
-- Show adapter name if model not available -- -- Show adapter name if model not available
local short_adapter = current_adapter:gsub("anthropic", "Claude"):gsub("openai", "OpenAI") -- local short_adapter = current_adapter:gsub("anthropic", "Claude"):gsub("openai", "OpenAI")
table.insert(status_parts, short_adapter) -- table.insert(status_parts, short_adapter)
end -- end
--
return table.concat(status_parts, " ") -- return table.concat(status_parts, " ")
end -- end
local colors = { local colors = {
blue = "#65D1FF", blue = "#65D1FF",
@@ -204,7 +204,8 @@ return {
}, },
lualine_x = { lualine_x = {
{ {
codecompanion_status, "codecompanion",
-- codecompanion_status,
color = { fg = colors.green }, color = { fg = colors.green },
}, },
{ {
@@ -218,13 +219,13 @@ return {
}) })
-- Create command to toggle short modes -- Create command to toggle short modes
vim.api.nvim_create_user_command('ToggleLualineShortModes', function() vim.api.nvim_create_user_command("ToggleLualineShortModes", function()
vim.g.lualine_use_short_modes = not vim.g.lualine_use_short_modes vim.g.lualine_use_short_modes = not vim.g.lualine_use_short_modes
require('lualine').refresh() require("lualine").refresh()
local status = vim.g.lualine_use_short_modes and 'short (single letter)' or 'full words' local status = vim.g.lualine_use_short_modes and "short (single letter)" or "full words"
vim.notify('Lualine modes set to ' .. status, vim.log.levels.INFO) vim.notify("Lualine modes set to " .. status, vim.log.levels.INFO)
end, { end, {
desc = 'Toggle between short and full mode names in lualine' desc = "Toggle between short and full mode names in lualine",
}) })
end, end,
} }