update codecompanion fidget spinner
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
local progress = require("fidget.progress")
|
||||
|
||||
local notify = require("notify")
|
||||
local spinner_frames = { "⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏" }
|
||||
local M = {}
|
||||
|
||||
function M:init()
|
||||
@@ -40,31 +40,46 @@ function M:pop_progress_handle(id)
|
||||
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 .. ")")
|
||||
local title = " Requesting assistance (" .. request.data.strategy .. ")"
|
||||
local idx = 1
|
||||
local notification_id = notify(spinner_frames[idx] .. " In progress...", "info", { title = title, timeout = false })
|
||||
local handle = { notification_id = notification_id, title = title }
|
||||
local timer = vim.loop.new_timer()
|
||||
if timer == nil then
|
||||
return
|
||||
end
|
||||
return table.concat(parts, " ")
|
||||
timer:start(
|
||||
0,
|
||||
100,
|
||||
vim.schedule_wrap(function()
|
||||
idx = idx % #spinner_frames + 1
|
||||
local new_id = notify(
|
||||
spinner_frames[idx] .. " In progress...",
|
||||
"info",
|
||||
{ replace = handle.notification_id, title = title, timeout = false }
|
||||
)
|
||||
handle.notification_id = new_id
|
||||
end)
|
||||
)
|
||||
handle.timer = timer
|
||||
handle.finish = function()
|
||||
if handle.timer then
|
||||
handle.timer:stop()
|
||||
handle.timer:close()
|
||||
handle.timer = nil
|
||||
end
|
||||
end
|
||||
return handle
|
||||
end
|
||||
|
||||
function M:report_exit_status(handle, request)
|
||||
local title = handle.title or (" Requesting assistance (" .. request.data.strategy .. ")")
|
||||
if request.data.status == "success" then
|
||||
handle.message = "Completed"
|
||||
notify("Completed", "info", { replace = handle.notification_id, title = title })
|
||||
elseif request.data.status == "error" then
|
||||
handle.message = " Error"
|
||||
notify(" Error", "error", { replace = handle.notification_id, title = title })
|
||||
else
|
||||
handle.message = " Cancelled"
|
||||
notify(" Cancelled", "warn", { replace = handle.notification_id, title = title })
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user