-
-
Save clason/1fe0f77ed3cc810ff75429edf1c56409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local LspProgress = require('lualine.component'):extend() | |
LspProgress.init = function(self, options) | |
LspProgress.super.init(self, options) | |
self:register_progress() | |
end | |
LspProgress.update_status = function(self) | |
self:update_progress() | |
return self.progress_message | |
end | |
LspProgress.register_progress = function(self) | |
self.clients = {} | |
self.progress_callback = function(_, msg, info) | |
local key = msg.token | |
if key then | |
local client_key = tostring(info.client_id) | |
if not self.clients[client_key] then | |
self.clients[client_key] = { progress = {}, name = vim.lsp.get_client_by_id(info.client_id).name } | |
end | |
local progress_collection = self.clients[client_key].progress | |
if not progress_collection[key] then | |
progress_collection[key] = { title = nil, message = nil, percentage = nil } | |
end | |
local progress = progress_collection[key] | |
local val = msg.value | |
if val.kind == 'begin' then | |
progress.title = val.title | |
progress.message = 'starting' | |
elseif val.kind == 'report' then | |
progress.percentage = val.percentage | |
progress.message = val.message | |
elseif val.kind == 'end' then | |
progress.percentage = '100' | |
progress.message = 'done' | |
vim.defer_fn(function() self.clients[client_key] = nil end, 1000) | |
end | |
end | |
end | |
vim.lsp.handlers['$/progress'] = self.progress_callback | |
end | |
LspProgress.update_progress = function(self) | |
local result = {} | |
for _, client in pairs(self.clients) do | |
table.insert(result, client.name) | |
table.insert(result, ': ') | |
for _, progress in pairs(client.progress) do | |
if progress.title and progress.title ~= '' then | |
table.insert(result, progress.title) | |
table.insert(result, ' ') | |
end | |
if progress.percentage and progress.percentage ~= '' then | |
table.insert(result, progress.percentage) | |
table.insert(result, '%% ') | |
end | |
if progress.message and progress.message ~= '' then | |
table.insert(result, '(') | |
table.insert(result, progress.message) | |
table.insert(result, ')') | |
end | |
end | |
end | |
self.progress_message = table.concat(result) | |
end | |
return LspProgress |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment