|
| 1 | +local state = { lsp_msg = "" } |
| 2 | +local spinners = { "", "", "", "", "", "", "", "", "", "" } |
| 3 | +vim.api.nvim_create_autocmd("LspProgress", { |
| 4 | + pattern = { "begin", "report", "end" }, |
| 5 | + callback = function(args) |
| 6 | + -- Ensure params exists before accessing its fields |
| 7 | + if not args.data or not args.data.params then |
| 8 | + return |
| 9 | + end |
| 10 | + |
| 11 | + local data = args.data.params.value |
| 12 | + local progress = "" |
| 13 | + |
| 14 | + if data.percentage then |
| 15 | + local idx = math.max(1, math.floor(data.percentage / 10)) |
| 16 | + local icon = spinners[idx] |
| 17 | + progress = icon .. " " .. data.percentage .. "%% " |
| 18 | + end |
| 19 | + |
| 20 | + local loaded_count = data.message and string.match(data.message, "^(%d+/%d+)") or "" |
| 21 | + local str = progress .. (data.title or "") .. " " .. (loaded_count or "") |
| 22 | + state.lsp_msg = data.kind == "end" and "" or str |
| 23 | + vim.cmd.redrawstatus() |
| 24 | + end, |
| 25 | +}) |
| 26 | + |
| 27 | +local lsp_msg = function() |
| 28 | + return vim.o.columns < 120 and "" or state.lsp_msg |
| 29 | +end |
1 | 30 | return function() |
2 | 31 | local has_catppuccin = vim.g.colors_name:find("catppuccin") ~= nil |
3 | 32 | local colors = require("modules.utils").get_palette() |
@@ -180,7 +209,12 @@ return function() |
180 | 209 | end |
181 | 210 | end |
182 | 211 | return next(available_servers) == nil and icons.misc.NoActiveLsp |
183 | | - or string.format("%s[%s]", icons.misc.LspAvailable, table.concat(available_servers, ", ")) |
| 212 | + or string.format( |
| 213 | + "%s[%s] %s", |
| 214 | + icons.misc.LspAvailable, |
| 215 | + table.concat(available_servers, ", "), |
| 216 | + lsp_msg() |
| 217 | + ) |
184 | 218 | end, |
185 | 219 | color = utils.gen_hl("blue", true, true, nil, "bold"), |
186 | 220 | cond = conditionals.has_enough_room, |
|
0 commit comments