nvim: lsp/statusline: Add support for LSP progress

Use the same timer loop for updating LSP progress in status line
which we use for updating git ahead, behind status.
This commit is contained in:
Sanchayan Maity 2023-06-22 17:49:20 +05:30
parent c1e4b234fb
commit 0265000a4f
Signed by: sanchayanmaity
GPG key ID: 6F6A0609C12038F3
2 changed files with 31 additions and 5 deletions

View file

@ -1,8 +1,10 @@
local fn = vim.fn
local api = vim.api
local gstatus = { ahead = 0, behind = 0 }
local update_gstatus = function()
local lsp_status = ""
local gstatus = { ahead = 0, behind = 0 }
local update_status = function()
local Job = require 'plenary.job'
Job:new({
command = 'git',
@ -20,16 +22,19 @@ local update_gstatus = function()
gstatus = { ahead = ahead, behind = behind }
end,
}):start()
if vim.lsp.status then
lsp_status = vim.lsp.status()
end
end
if _G.Gstatus_timer == nil then
_G.Gstatus_timer = vim.uv.new_timer()
_G.Gstatus_timer:start(0, 1000, vim.schedule_wrap(update_status))
else
_G.Gstatus_timer:stop()
end
_G.Gstatus_timer:start(0, 2000, vim.schedule_wrap(update_gstatus))
local M = {}
local colors = {
@ -70,10 +75,12 @@ highlight("DiagnosticsH", colors.orange , colors.bg)
highlight("Location" , colors.yellow , colors.bg)
highlight("Progress" , colors.magenta, colors.bg)
highlight("WinbarFile" , colors.magenta, colors.bg)
highlight("LspProgress" , colors.orange , colors.bg)
M.trunc_width = setmetatable({
git_status = 60,
filename = 140,
git_status = 60,
lsp_status = 80,
}, {
__index = function()
return 80
@ -204,12 +211,26 @@ M.git_ahead_behind_status = function()
or ""
end
M.get_lsp_status = function(self)
local trunc_width = self.trunc_width.lsp_status
if self:is_truncated(trunc_width) then
return ""
end
if vim.lsp.status then
return string.format(" %s%s", '%#LspProgress#', string.sub(lsp_status, 1, trunc_width))
end
return ""
end
M.set_active = function(self)
return table.concat {
self:get_filename(),
self:get_git_status(),
self:git_ahead_behind_status(),
"%=",
self:get_lsp_status(),
self:diagnostic_status(),
self:get_line_col(),
self:progress(),

View file

@ -233,3 +233,8 @@ vim.api.nvim_create_autocmd("LspDetach", {
client_custom_cleanup(client)
end,
})
vim.api.nvim_create_autocmd("LspProgress", {
group = lsp_augroup_id,
command = "redrawstatus"
})