Removing redundant code from statusline
This commit is contained in:
@@ -81,7 +81,7 @@ local function update_git_branch()
|
|||||||
end
|
end
|
||||||
)
|
)
|
||||||
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' }, {
|
vim.api.nvim_create_autocmd({ 'BufEnter', 'FocusGained' }, {
|
||||||
callback = function()
|
callback = function()
|
||||||
update_git_branch()
|
update_git_branch()
|
||||||
@@ -108,19 +108,15 @@ local function start_progress_timer()
|
|||||||
end
|
end
|
||||||
if next(progress) then
|
if next(progress) then
|
||||||
frame = (frame % #spinner_frames) + 1
|
frame = (frame % #spinner_frames) + 1
|
||||||
-- vim.cmd('redrawstatus')
|
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.cmd('redrawstatus')
|
vim.cmd('redrawstatus')
|
||||||
end)
|
end)
|
||||||
-- else
|
|
||||||
else
|
else
|
||||||
progress_timer:stop()
|
progress_timer:stop()
|
||||||
vim.schedule(function()
|
vim.schedule(function()
|
||||||
vim.cmd('redrawstatus')
|
vim.cmd('redrawstatus')
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
-- progress_timer:stop()
|
|
||||||
-- end
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -163,35 +159,9 @@ vim.api.nvim_create_autocmd('LspProgress', {
|
|||||||
end
|
end
|
||||||
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' }, {
|
vim.api.nvim_create_autocmd({ 'LspAttach', 'LspDetach' }, {
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
-- vim.schedule(function()
|
|
||||||
local names = {}
|
local names = {}
|
||||||
for _, c in ipairs(vim.lsp.get_clients({ bufnr = args.buf })) do
|
for _, c in ipairs(vim.lsp.get_clients({ bufnr = args.buf })) do
|
||||||
table.insert(names, c.name)
|
table.insert(names, c.name)
|
||||||
@@ -199,36 +169,16 @@ vim.api.nvim_create_autocmd({ 'LspAttach', 'LspDetach' }, {
|
|||||||
vim.b[args.buf].lsp_names = #names > 0
|
vim.b[args.buf].lsp_names = #names > 0
|
||||||
and (' ● ' .. table.concat(names, ', ') .. ' ')
|
and (' ● ' .. table.concat(names, ', ') .. ' ')
|
||||||
or ''
|
or ''
|
||||||
-- end)
|
|
||||||
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()
|
local function lsp_section()
|
||||||
-- Only check progress for this buffer's clients
|
|
||||||
local client_ids = {}
|
local client_ids = {}
|
||||||
for _, c in
|
for _, c in
|
||||||
ipairs(vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() }))
|
ipairs(vim.lsp.get_clients({ bufnr = vim.api.nvim_get_current_buf() }))
|
||||||
do
|
do
|
||||||
client_ids[c.id] = true
|
client_ids[c.id] = true
|
||||||
end
|
end
|
||||||
-- Filter progress by current buffer's clients
|
|
||||||
local latest = nil
|
local latest = nil
|
||||||
for key, p in pairs(progress) do
|
for key, p in pairs(progress) do
|
||||||
local cid = tonumber(key:match('^(%d+):'))
|
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
|
if latest and (not latest.done or (vim.loop.now() - latest.t < 2000)) then
|
||||||
return '%#StatusLspSpinner# ○ ' .. latest.msg .. ' %*'
|
return '%#StatusLspSpinner# ○ ' .. latest.msg .. ' %*'
|
||||||
end
|
end
|
||||||
-- Use the cached names from the autocmd
|
|
||||||
return '%#StatusLsp#' .. (vim.b.lsp_names or '') .. '%*'
|
return '%#StatusLsp#' .. (vim.b.lsp_names or '') .. '%*'
|
||||||
end
|
end
|
||||||
--- Diagnostics summary.
|
|
||||||
local diag_cache = {}
|
local diag_cache = {}
|
||||||
local function update_diag_cache(ev)
|
local function build_diag_string(counts)
|
||||||
local bufnr = ev.buf
|
|
||||||
local counts = vim.diagnostic.count(bufnr)
|
|
||||||
local parts = {}
|
local parts = {}
|
||||||
if counts[1] and counts[1] > 0 then
|
if counts[1] and counts[1] > 0 then
|
||||||
table.insert(parts, '%#StatusDiagError# E' .. counts[1] .. ' %*')
|
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
|
if counts[4] and counts[4] > 0 then
|
||||||
table.insert(parts, '%#StatusDiagHint# H' .. counts[4] .. ' %*')
|
table.insert(parts, '%#StatusDiagHint# H' .. counts[4] .. ' %*')
|
||||||
end
|
end
|
||||||
diag_cache[bufnr] = table.concat(parts)
|
return table.concat(parts)
|
||||||
end
|
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(
|
vim.api.nvim_create_autocmd(
|
||||||
'DiagnosticChanged',
|
'DiagnosticChanged',
|
||||||
{ callback = update_diag_cache }
|
{ callback = update_diag_cache }
|
||||||
)
|
)
|
||||||
|
|
||||||
--- Main statusline renderer.
|
|
||||||
function _G.__statusline()
|
function _G.__statusline()
|
||||||
local m = vim.fn.mode()
|
local m = vim.fn.mode()
|
||||||
local mode_hl = mode_hl_map[m] or 'StatusModeNormal'
|
local mode_hl = mode_hl_map[m] or 'StatusModeNormal'
|
||||||
@@ -279,24 +228,7 @@ function _G.__statusline()
|
|||||||
git ~= '' and ('%#StatusGit# ' .. git .. ' %*') or '',
|
git ~= '' and ('%#StatusGit# ' .. git .. ' %*') or '',
|
||||||
lsp_section(),
|
lsp_section(),
|
||||||
'%=',
|
'%=',
|
||||||
-- diag_cache[cur_buf] or '', -- Per-buffer cache lookup
|
diag_cache[cur_buf] or build_diag_string(vim.diagnostic.count(cur_buf)),
|
||||||
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)(),
|
|
||||||
'%#StatusCursor# %l:%-2c %*',
|
'%#StatusCursor# %l:%-2c %*',
|
||||||
'%#' .. mode_hl .. '# %p%% %*',
|
'%#' .. mode_hl .. '# %p%% %*',
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user