Skip to content

Commit e017c5a

Browse files
committed
refactor(lualine): inline chat_progress and improve LSP progress display
1 parent de16945 commit e017c5a

File tree

2 files changed

+55
-71
lines changed

2 files changed

+55
-71
lines changed

lua/modules/configs/ui/lualine/init.lua renamed to lua/modules/configs/ui/lualine.lua

Lines changed: 55 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
11
local lsp_state = { progress = "" }
2-
local spinners = { "", "󰪞", "󰪟", "󰪠", "󰪡", "󰪢", "󰪣", "󰪤", "󰪥", "" }
2+
local spinners = { "", "󰪞", "󰪟", "󰪠", "󰪡", "󰪢", "󰪣", "󰪤", "󰪥", "", "" }
33

44
vim.api.nvim_create_autocmd("LspProgress", {
55
group = vim.api.nvim_create_augroup("LualineLspProgress", { clear = true }),
66
pattern = { "begin", "report", "end" },
77
callback = function(args)
8-
-- Ensure params exists before accessing its fields
9-
if not args.data or not args.data.params then
8+
-- Get the payload
9+
local data = args.data and args.data.params and args.data.params.value
10+
if not data then
1011
return
1112
end
1213

13-
local data = args.data.params.value
14-
local progress = ""
14+
-- If it's the end event, clear; else build "<spinner> XX% <title> <loaded>"
15+
if data.kind == "end" then
16+
lsp_state.progress = ""
17+
else
18+
local pct = data.percentage or 0
19+
local idx = 1 + ((pct - pct % 10) / 10)
20+
local spinner = spinners[idx]
21+
22+
local progress = ""
23+
if data.message then
24+
local start, stop = data.message:find("^%d+/%d+")
25+
if start then
26+
progress = data.message:sub(start, stop)
27+
end
28+
end
1529

16-
if data.percentage then
17-
local idx = math.max(1, math.floor(data.percentage / 10))
18-
local icon = spinners[idx]
19-
progress = icon .. " " .. data.percentage .. "%% "
30+
lsp_state.progress = spinner
31+
.. " "
32+
.. tostring(pct)
33+
.. "%% "
34+
.. (data.title or "")
35+
.. (progress ~= "" and " " .. progress or "")
2036
end
2137

22-
local loaded_count = data.message and string.match(data.message, "^(%d+/%d+)") or ""
23-
local str = progress .. (data.title or "") .. " " .. (loaded_count or "")
24-
lsp_state.progress = data.kind == "end" and "" or str
38+
-- Redraw statusline
2539
pcall(vim.cmd.redrawstatus)
2640
end,
2741
})
@@ -35,6 +49,7 @@ return function()
3549
git_nosep = require("modules.utils.icons").get("git"),
3650
misc = require("modules.utils.icons").get("misc", true),
3751
ui = require("modules.utils.icons").get("ui", true),
52+
aichat = require("modules.utils.icons").get("aichat", true),
3853
}
3954

4055
local function custom_theme()
@@ -121,7 +136,7 @@ return function()
121136
---@param special_nobg boolean @Disable guibg for transparent backgrounds?
122137
---@param bg string? @Background hl group
123138
---@param gui string? @GUI highlight arguments
124-
---@return fun():lualine_hlgrp|nil
139+
---@return nil|fun():lualine_hlgrp
125140
gen_hl = function(fg, gen_bg, special_nobg, bg, gui)
126141
if has_catppuccin then
127142
return function()
@@ -140,10 +155,6 @@ return function()
140155
end,
141156
}
142157

143-
local function lsp_progress()
144-
return conditionals.has_enough_room() and lsp_state.progress or ""
145-
end
146-
147158
local function diff_source()
148159
local gitsigns = vim.b.gitsigns_status_dict
149160
if gitsigns then
@@ -217,13 +228,38 @@ return function()
217228
"%s[%s] %s",
218229
icons.misc.LspAvailable,
219230
table.concat(available_servers, ", "),
220-
lsp_progress()
231+
lsp_state.progress
221232
)
222233
end,
223234
color = utils.gen_hl("blue", true, true, nil, "bold"),
224235
cond = conditionals.has_enough_room,
225236
},
226237

238+
chat_progress = {
239+
(function()
240+
local processing = false
241+
local animate_chars = { "", "", "", "", "", "", "", "", "", "" }
242+
local animation_idx = 1
243+
vim.api.nvim_create_autocmd("User", {
244+
pattern = { "CodeCompanionRequestStarted", "CodeCompanionRequestFinished" },
245+
group = vim.api.nvim_create_augroup("CodeCompanionHooks", { clear = true }),
246+
callback = function(args)
247+
processing = (args.match == "CodeCompanionRequestStarted")
248+
end,
249+
})
250+
251+
return function()
252+
if not processing then
253+
return ""
254+
end
255+
animation_idx = animation_idx % #animate_chars + 1
256+
return string.format("%s %s", icons.aichat.Copilot, animate_chars[animation_idx])
257+
end
258+
end)(),
259+
color = utils.gen_hl("yellow", true, true),
260+
cond = conditionals.has_enough_room,
261+
},
262+
227263
python_venv = {
228264
function()
229265
local function env_cleanup(venv)
@@ -345,10 +381,7 @@ return function()
345381
components.lsp,
346382
},
347383
lualine_x = {
348-
{
349-
require("modules.configs.ui.lualine.components.chat_progress"),
350-
color = utils.gen_hl("yellow", true, true),
351-
},
384+
components.chat_progress,
352385
{
353386
"encoding",
354387
show_bomb = true,

lua/modules/configs/ui/lualine/components/chat_progress.lua

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)