From da73c6c3330352692711c9ad10d91830b28ff9a4 Mon Sep 17 00:00:00 2001 From: Hendra Date: Sat, 15 Mar 2025 12:02:58 +0700 Subject: [PATCH] Update --- lua/custom/plugins/avante.lua | 2 +- lua/custom/plugins/codecompanion.lua | 9 +++ .../plugins/codecompanion/fidget-spinner.lua | 73 +++++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 lua/custom/plugins/codecompanion/fidget-spinner.lua diff --git a/lua/custom/plugins/avante.lua b/lua/custom/plugins/avante.lua index 2f0a6d53..61665f3e 100644 --- a/lua/custom/plugins/avante.lua +++ b/lua/custom/plugins/avante.lua @@ -1,7 +1,7 @@ return { 'yetone/avante.nvim', event = 'VeryLazy', - lazy = false, + lazy = true, version = false, -- set this if you want to always pull the latest change opts = { -- add any opts here diff --git a/lua/custom/plugins/codecompanion.lua b/lua/custom/plugins/codecompanion.lua index 068d4fbc..fe92c474 100644 --- a/lua/custom/plugins/codecompanion.lua +++ b/lua/custom/plugins/codecompanion.lua @@ -3,9 +3,13 @@ return { dependencies = { 'nvim-lua/plenary.nvim', 'nvim-treesitter/nvim-treesitter', + 'j-hui/fidget.nvim', -- The following are optional: { 'MeanderingProgrammer/render-markdown.nvim', ft = { 'markdown', 'codecompanion' } }, }, + init = function() + require('custom.plugins.codecompanion.fidget-spinner'):init() + end, config = function() require('codecompanion').setup { adapters = { @@ -14,6 +18,11 @@ return { api_key = 'CODECOMP_ANTHROPIC_API_KEY', }, }), + deepseek = require('codecompanion.adapters').extend('deepseek', { + env = { + api_key = 'CODECOMP_DEEPSEEK_API_KEY', + }, + }), }, strategies = { chat = { diff --git a/lua/custom/plugins/codecompanion/fidget-spinner.lua b/lua/custom/plugins/codecompanion/fidget-spinner.lua new file mode 100644 index 00000000..04556d8c --- /dev/null +++ b/lua/custom/plugins/codecompanion/fidget-spinner.lua @@ -0,0 +1,73 @@ +-- lua/plugins/codecompanion/fidget-spinner.lua + +local progress = require 'fidget.progress' + +local M = {} + +function M:init() + local group = vim.api.nvim_create_augroup('CodeCompanionFidgetHooks', {}) + + vim.api.nvim_create_autocmd({ 'User' }, { + pattern = 'CodeCompanionRequestStarted', + group = group, + callback = function(request) + local handle = M:create_progress_handle(request) + M:store_progress_handle(request.data.id, handle) + end, + }) + + vim.api.nvim_create_autocmd({ 'User' }, { + pattern = 'CodeCompanionRequestFinished', + group = group, + callback = function(request) + local handle = M:pop_progress_handle(request.data.id) + if handle then + M:report_exit_status(handle, request) + handle:finish() + end + end, + }) +end + +M.handles = {} + +function M:store_progress_handle(id, handle) + M.handles[id] = handle +end + +function M:pop_progress_handle(id) + local handle = M.handles[id] + M.handles[id] = nil + return handle +end + +function M:create_progress_handle(request) + return progress.handle.create { + title = ' Requesting assistance (' .. request.data.strategy .. ')', + message = 'In progress...', + lsp_client = { + name = M:llm_role_title(request.data.adapter), + }, + } +end + +function M:llm_role_title(adapter) + local parts = {} + table.insert(parts, adapter.formatted_name) + if adapter.model and adapter.model ~= '' then + table.insert(parts, '(' .. adapter.model .. ')') + end + return table.concat(parts, ' ') +end + +function M:report_exit_status(handle, request) + if request.data.status == 'success' then + handle.message = 'Completed' + elseif request.data.status == 'error' then + handle.message = ' Error' + else + handle.message = '󰜺 Cancelled' + end +end + +return M