Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1105 : check for LSP progress, report working/linted file #1144

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion lua/lualine/components/diagnostics/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ M.symbols = {
warn = '󰀪 ', -- x000f002a
info = '󰋽 ', -- x000f02fd
hint = '󰌶 ', -- x000f0336
ok = '󰗡 ', -- x000f05e1
working = '󰮍 ', -- x00f0b8d
},
no_icons = { error = 'E:', warn = 'W:', info = 'I:', hint = 'H:' },
no_icons = { error = 'E:', warn = 'W:', info = 'I:', hint = 'H:', ok = 'OK', working = '..' },
}

-- default options for diagnostics component
Expand Down Expand Up @@ -52,6 +54,20 @@ function M.apply_default_colors(opts)
'#273faf'
),
},
ok = {
fg = utils.extract_color_from_hllist(
{ 'fg', 'sp' },
{ 'DiagnosticOk', 'LspDiagnosticsDefaultOk', 'DiffAdd' },
'#a4cc35'
),
},
working = {
fg = utils.extract_color_from_hllist(
{ 'fg', 'sp' },
{ 'DiagnosticWorking', 'LspDiagnosticsDefaultWorking', 'Title' },
'#66bfff'
),
},
}
opts.diagnostics_color = vim.tbl_deep_extend('keep', opts.diagnostics_color or {}, default_diagnostics_color)
end
Expand Down
28 changes: 28 additions & 0 deletions lua/lualine/components/diagnostics/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function M:init(options)
warn = self:create_hl(self.options.diagnostics_color.warn, 'warn'),
info = self:create_hl(self.options.diagnostics_color.info, 'info'),
hint = self:create_hl(self.options.diagnostics_color.hint, 'hint'),
ok = self:create_hl(self.options.diagnostics_color.ok, 'ok'),
working = self:create_hl(self.options.diagnostics_color.working, 'working'),
}
end

Expand All @@ -48,12 +50,25 @@ function M:init(options)
'### diagnostics.sources\n\nno sources for diagnostics configured.\nPlease specify which diagnostics source you want lualine to use with `sources` option.\n'
)
end

-- Check if a language server reports working progress.
self.lsp_started = false
self.lsp_working = false
vim.lsp.handlers["$/progress"] = function(_, result)
self.lsp_started = true
if result.value.kind == "end" then
self.lsp_working = false
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gopls will emit a "begin" event when encountering an issue loading workspace, with no followup "end". In order to recover from bad actors, LSP progress handlers need to implement a debounced clear routine.

else
self.lsp_working = true
end
end
end

function M:update_status()
local bufnr = vim.api.nvim_get_current_buf()
local diagnostics_count
local result = {}
local ok_count = 0
if self.options.update_in_insert or vim.api.nvim_get_mode().mode:sub(1, 1) ~= 'i' then
local error_count, warning_count, info_count, hint_count = 0, 0, 0, 0
local diagnostic_data = modules.sources.get_diagnostics(self.options.sources)
Expand All @@ -64,6 +79,9 @@ function M:update_status()
info_count = info_count + data.info
hint_count = hint_count + data.hint
end
if error_count + warning_count + info_count + hint_count == 0 then
ok_count = 1
end
diagnostics_count = {
error = error_count,
warn = warning_count,
Expand Down Expand Up @@ -98,12 +116,22 @@ function M:update_status()
table.insert(result, colors[section] .. padding .. self.symbols[section] .. diagnostics_count[section])
end
end
if self.lsp_working then
table.insert(result, colors['working'] .. self.symbols['working'])
elseif self.lsp_started and ok_count == 1 then
table.insert(result, colors['ok'] .. self.symbols['ok'])
end
else
for _, section in ipairs(self.options.sections) do
if diagnostics_count[section] ~= nil and (always_visible or diagnostics_count[section] > 0) then
table.insert(result, self.symbols[section] .. diagnostics_count[section])
end
end
if self.lsp_working then
table.insert(result, self.symbols['working'])
elseif self.lsp_started and ok_count == 1 then
table.insert(result, self.symbols['ok'])
end
end
return table.concat(result, ' ')
end
Expand Down