Replies: 8 comments 15 replies
-
Awesome and thanks for sharing. That looks so clean. I'm going to start labelling discussions so others can find them more easily. |
Beta Was this translation helpful? Give feedback.
-
Would this make sense here? |
Beta Was this translation helpful? Give feedback.
-
A spinner indicating request status is a great addition, especially for non-streaming functionality. If you're considering adding this to It's a single-file utility designed for easy integration into plugin codebases. |
Beta Was this translation helpful? Give feedback.
-
Hi! Sorry for chiming in but I do have a similar question request: in https://github.com/jackMort/ChatGPT.nvim there is a visual indicator that the LLM is "Loading...". Can a similar thing be added (is already present?) in code companion? In the following GIF you can see how ChatGPT.nvim does this loading reporting and then how CodeCompanion works (with no indicator): I can open a separate issue @olimorris if this is not the place to discuss this. |
Beta Was this translation helpful? Give feedback.
-
Well, I’ve created something different for this: (focus on the cursor): it can be implemented as an opt-in feature for codecompanion. Screen.Recording.2025-02-03.at.11.46.08.PM.mov |
Beta Was this translation helpful? Give feedback.
-
Hi All! In case you have not seen this @olimorris, there is now a tracking issue in neovim for implementing primitives used by plugins such as this one: neovim/neovim#32084 It specifically mentions an nvim api for status/progress notifications, hence it might be relevant here. Also if you have anything that you might find useful, that might be a good place to chime in :) |
Beta Was this translation helpful? Give feedback.
-
6/9 Update spinner.lua local M = {
processing = false,
spinner_index = 1,
namespace_id = nil,
timer = nil,
spinner_symbols = {
"⠋",
"⠙",
"⠹",
"⠸",
"⠼",
"⠴",
"⠦",
"⠧",
"⠇",
"⠏",
},
filetype = "codecompanion",
}
function M:get_buf(filetype)
for _, buf in ipairs(vim.api.nvim_list_bufs()) do
if vim.api.nvim_buf_is_valid(buf) and vim.bo[buf].filetype == filetype then
return buf
end
end
return nil
end
function M:update_spinner()
if not self.processing then
self:stop_spinner()
return
end
self.spinner_index = (self.spinner_index % #self.spinner_symbols) + 1
local buf = self:get_buf(self.filetype)
if buf == nil then
return
end
-- Clear previous virtual text
vim.api.nvim_buf_clear_namespace(buf, self.namespace_id, 0, -1)
local last_line = vim.api.nvim_buf_line_count(buf) - 1
vim.api.nvim_buf_set_extmark(buf, self.namespace_id, last_line, 0, {
virt_lines = { { { self.spinner_symbols[self.spinner_index] .. " Processing...", "Comment" } } },
virt_lines_above = true, -- false means below the line
})
end
function M:start_spinner()
self.processing = true
self.spinner_index = 0
if self.timer then
self.timer:stop()
self.timer:close()
self.timer = nil
end
self.timer = vim.loop.new_timer()
self.timer:start(
0,
100,
vim.schedule_wrap(function()
self:update_spinner()
end)
)
end
function M:stop_spinner()
self.processing = false
if self.timer then
self.timer:stop()
self.timer:close()
self.timer = nil
end
local buf = self:get_buf(self.filetype)
if buf == nil then
return
end
vim.api.nvim_buf_clear_namespace(buf, self.namespace_id, 0, -1)
end
function M:init()
-- Create namespace for virtual text
self.namespace_id = vim.api.nvim_create_namespace("CodeCompanionSpinner")
vim.api.nvim_create_augroup("CodeCompanionHooks", { clear = true })
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:start_spinner()
elseif request.match == "CodeCompanionRequestFinished" then
self:stop_spinner()
end
end,
})
end
return M and modify the send commend send = {
callback = function(chat)
vim.cmd("stopinsert")
chat:submit()
chat:add_buf_message({ role = "llm", content = "" })
end,
index = 1,
description = "Send",
}, init the spinner in config config = function(_, opts)
local spinner = require("plugins.code-companion.spinner")
spinner:init()
-- Setup the entire opts table
require("codecompanion").setup(opts)
end, |
Beta Was this translation helpful? Give feedback.
-
Hi all, I extended the code above from @yuhua99 to handle parallel requests in multiple chats and wrapped it into a plugin called codecompanion-spinner to simplify the usage for other users. I hope it is useful for someone! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Here is a simple integration with
fidget.nvim
[1] for progress reporting:example.mp4
Currently this uses fidget's API directly. I did not look into this but there may also be a nvim-level API for LSP progress reporting, which potentially would allow for support for other status/notification plugins.
Please let me know if you want this somewhere (As an example, or integrated) - happy to PR.
[1] https://github.com/j-hui/fidget.nvim
Beta Was this translation helpful? Give feedback.
All reactions