Removing redundant code from statusline

This commit is contained in:
Andrew Haynes
2026-05-10 03:45:41 -04:00
parent 86d6e13813
commit 295aa41395
+9 -77
View File
@@ -81,7 +81,7 @@ local function update_git_branch()
end
)
end
vim.uv.new_timer():start(5000, 5000, vim.schedule_wrap(update_git_branch))
vim.uv.new_timer():start(5000, 5000, update_git_branch)
vim.api.nvim_create_autocmd({ 'BufEnter', 'FocusGained' }, {
callback = function()
update_git_branch()
@@ -108,19 +108,15 @@ local function start_progress_timer()
end
if next(progress) then
frame = (frame % #spinner_frames) + 1
-- vim.cmd('redrawstatus')
vim.schedule(function()
vim.cmd('redrawstatus')
end)
-- else
else
progress_timer:stop()
vim.schedule(function()
vim.cmd('redrawstatus')
end)
end
-- progress_timer:stop()
-- end
end)
end
end
@@ -163,35 +159,9 @@ vim.api.nvim_create_autocmd('LspProgress', {
end
end,
})
-- local frame = 0
-- --- Clean stale progress messages periodically
-- vim.uv.new_timer():start(
-- 0,
-- 200,
-- vim.schedule_wrap(function()
-- if next(progress) == nil then
-- return progress_timer:stop()
-- -- end
-- -- else -- no progress
-- -- progress_timer:stop()
-- end
-- local now = vim.loop.now()
-- for k, v in pairs(progress) do
-- local ttl = v.done and 2000 or 10000
-- if now - v.t > ttl then
-- progress[k] = nil
-- end
-- end
-- if next(progress) then
-- frame = (frame % #spinner_frames) + 1
-- end
-- vim.cmd('redrawstatus')
-- end)
-- )
--- Build the LSP section of the statusline
vim.api.nvim_create_autocmd({ 'LspAttach', 'LspDetach' }, {
callback = function(args)
-- vim.schedule(function()
local names = {}
for _, c in ipairs(vim.lsp.get_clients({ bufnr = args.buf })) do
table.insert(names, c.name)
@@ -199,36 +169,16 @@ vim.api.nvim_create_autocmd({ 'LspAttach', 'LspDetach' }, {
vim.b[args.buf].lsp_names = #names > 0
and (' ● ' .. table.concat(names, ', ') .. ' ')
or ''
-- end)
end,
})
-- local function lsp_section()
-- -- Only check for progress (dynamic)
-- local latest = nil
-- for _, p in pairs(progress) do
-- -- Simplified check: show latest active or recently done
-- if not latest or p.t > latest.t then
-- latest = p
-- end
-- end
--
-- if latest and (not latest.done or (vim.loop.now() - latest.t < 2000)) then
-- return '%#StatusLspSpinner# ○ ' .. latest.msg .. ' %*'
-- end
--
-- -- Use the cached names from the autocmd
-- return '%#StatusLsp#' .. (vim.b.lsp_names or '') .. '%*'
-- end
local function lsp_section()
-- Only check progress for this buffer's clients
local client_ids = {}
for _, c in
ipairs(vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() }))
do
client_ids[c.id] = true
end
-- Filter progress by current buffer's clients
local latest = nil
for key, p in pairs(progress) do
local cid = tonumber(key:match('^(%d+):'))
@@ -241,14 +191,11 @@ local function lsp_section()
if latest and (not latest.done or (vim.loop.now() - latest.t < 2000)) then
return '%#StatusLspSpinner# ○ ' .. latest.msg .. ' %*'
end
-- Use the cached names from the autocmd
return '%#StatusLsp#' .. (vim.b.lsp_names or '') .. '%*'
end
--- Diagnostics summary.
local diag_cache = {}
local function update_diag_cache(ev)
local bufnr = ev.buf
local counts = vim.diagnostic.count(bufnr)
local function build_diag_string(counts)
local parts = {}
if counts[1] and counts[1] > 0 then
table.insert(parts, '%#StatusDiagError# E' .. counts[1] .. ' %*')
@@ -259,15 +206,17 @@ local function update_diag_cache(ev)
if counts[4] and counts[4] > 0 then
table.insert(parts, '%#StatusDiagHint# H' .. counts[4] .. ' %*')
end
diag_cache[bufnr] = table.concat(parts)
return table.concat(parts)
end
local function update_diag_cache(ev)
diag_cache[ev.buf] = build_diag_string(vim.diagnostic.count(ev.buf))
end
vim.api.nvim_create_autocmd(
'DiagnosticChanged',
{ callback = update_diag_cache }
)
--- Main statusline renderer.
function _G.__statusline()
local m = vim.fn.mode()
local mode_hl = mode_hl_map[m] or 'StatusModeNormal'
@@ -279,24 +228,7 @@ function _G.__statusline()
git ~= '' and ('%#StatusGit#  ' .. git .. ' %*') or '',
lsp_section(),
'%=',
-- diag_cache[cur_buf] or '', -- Per-buffer cache lookup
diag_cache[cur_buf] or (function()
local parts = {}
local counts = vim.diagnostic.count(cur_buf)
if counts[1] and counts[1] > 0 then
table.insert(
parts,
'%#StatusDiagError# E' .. counts[1] .. ' %*'
)
end
if counts[2] and counts[2] > 0 then
table.insert(parts, '%#StatusDiagWarn# W' .. counts[2] .. ' %*')
end
if counts[4] and counts[4] > 0 then
table.insert(parts, '%#StatusDiagHint# H' .. counts[4] .. ' %*')
end
return table.concat(parts)
end)(),
diag_cache[cur_buf] or build_diag_string(vim.diagnostic.count(cur_buf)),
'%#StatusCursor# %l:%-2c %*',
'%#' .. mode_hl .. '# %p%% %*',
}