Skip to content

Commit

Permalink
use codecompanion, update nix flake
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishrb committed Sep 17, 2024
1 parent ec03f31 commit 959aa2b
Show file tree
Hide file tree
Showing 11 changed files with 226 additions and 54 deletions.
110 changes: 72 additions & 38 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,16 @@
url = "github:nvim-neotest/nvim-nio";
flake = false;
};
parrot-nvim = {
url = "github:frankroeder/parrot.nvim";
codecompanion-nvim = {
url = "github:olimorris/codecompanion.nvim";
flake = false;
};
dressing-nvim = {
url = "github:stevearc/dressing.nvim";
flake = false;
};
mini-diff = {
url = "github:echasnovski/mini.diff";
flake = false;
};

Expand Down
6 changes: 4 additions & 2 deletions modules/common/nvim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ let
nvim-nio
];
ai = with pkgs.vimPlugins; [
parrot-nvim
fzf-lua
codecompanion-nvim
dressing-nvim
mini-diff
copilot-lua
];
general = with pkgs.vimPlugins; {
theme = builtins.getAttr packageDef.categories.colorscheme {
Expand Down
2 changes: 1 addition & 1 deletion modules/common/nvim/lua/chrishrb/lsp/handlers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ local function lsp_keymaps(bufnr)
end

M.on_attach = function(client, bufnr)
if client.name == "tsserver" then
if client.name == "ts_ls" then
client.server_capabilities.document_formatting = false
end
lsp_keymaps(bufnr)
Expand Down
2 changes: 1 addition & 1 deletion modules/common/nvim/lua/chrishrb/lsp/mason.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ if nixCats("php") then
end

if nixCats("web") then
servers[#servers + 1] = "tsserver"
servers[#servers + 1] = "ts_ls"
servers[#servers + 1] = "tailwindcss"
servers[#servers + 1] = "volar"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local M = require("lualine.component"):extend()

M.processing = false
M.spinner_index = 1

local spinner_symbols = {
"",
"",
"",
"",
"",
"",
"",
"",
"",
"",
}
local spinner_symbols_len = 10

-- Initializer
function M:init(options)
M.super.init(self, options)

local group = vim.api.nvim_create_augroup("CodeCompanionHooks", {})

vim.api.nvim_create_autocmd({ "User" }, {
pattern = "CodeCompanionRequest*",
group = group,
callback = function(request)
if request.match == "CodeCompanionRequestStarted" then
self.processing = true
elseif request.match == "CodeCompanionRequestFinished" then
self.processing = false
end
end,
})
end

-- Function that runs every time statusline is updated
function M:update_status()
if self.processing then
self.spinner_index = (self.spinner_index % spinner_symbols_len) + 1
return spinner_symbols[self.spinner_index]
else
return nil
end
end

return M
48 changes: 48 additions & 0 deletions modules/common/nvim/lua/chrishrb/plugins/config/codecompanion.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
require("dressing").setup({
input = {
enabled = false
},
select = {
enabled = true
}
})

require("codecompanion").setup({
display = {
action_palette = {
prompt = "🤖 ~ "
}
},
strategies = {
chat = {
adapter = "copilot",
},
inline = {
adapter = "copilot",
},
agent = {
adapter = "copilot",
},
},
})

-- setup which-key mappings
local which_key = require("which-key")
which_key.add({
{
{ "<leader>c", group = "CodeCompanion (AI)", nowait = true, remap = false },
{ "<leader>cc", "<cmd>CodeCompanion<CR>", desc = "Quick chat", nowait = true, remap = false },
{ "<leader>ca", "<cmd>CodeCompanionActions<CR>", desc = "Actions", nowait = true, remap = false },
{ "<leader>co", "<cmd>CodeCompanionChat<CR>", desc = "New Chat", nowait = true, remap = false },
{ "<leader>ct", "<cmd>CodeCompanionToggle<CR>", desc = "Toggle chat", nowait = true, remap = false },
{
mode = { "v" },
{ "<leader>c", group = "CodeCompanion (AI)", nowait = true, remap = false },
{ "<leader>cc", ":CodeCompanion<CR>", desc = "Quick chat", nowait = true, remap = false },
{ "<leader>ca", ":CodeCompanionActions<CR>", desc = "Actions", nowait = true, remap = false },
},
}
})

-- Expand 'cc' into 'CodeCompanion' in the command line
vim.cmd([[cab cc CodeCompanion]])
7 changes: 7 additions & 0 deletions modules/common/nvim/lua/chrishrb/plugins/config/lualine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ local lsp = {
color = { bg = "#f38ba8", fg = "#1e1e2e" },
}

local codecompanion = {
require('chrishrb.plugins.config.codecompanion-lualine'),
color = { bg = "#b4befe", fg = "#313244" },
separator = { left = icons.ui.HalfCircleLeft },
}

require('lualine').setup {

options = {
Expand Down Expand Up @@ -165,6 +171,7 @@ require('lualine').setup {
space,
},
lualine_y = {
codecompanion,
encoding,
fileformat,
space,
Expand Down
Loading

0 comments on commit 959aa2b

Please sign in to comment.