Skip to content

Commit

Permalink
chore(nvim): Use new vim.diagnostic.count(0) in statusline
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjones2014 committed Jan 18, 2024
1 parent 1f48d7e commit 8bd2195
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
35 changes: 16 additions & 19 deletions nvim/lua/my/configure/heirline/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,22 @@ M.FilePath = {
}

local icons = require('my.lsp.icons')
local severities_order = { 'Hint', 'Information', 'Warning', 'Error' }
local severity_hl = { Hint = 'Hint', Information = 'Info', Warning = 'Warn', Error = 'Error' }
local severities = {
Hint = vim.diagnostic.severity.HINT,
Information = vim.diagnostic.severity.INFO,
Warning = vim.diagnostic.severity.WARN,
Error = vim.diagnostic.severity.ERROR,
local diagnostics_order = {
vim.diagnostic.severity.HINT,
vim.diagnostic.severity.INFO,
vim.diagnostic.severity.WARN,
vim.diagnostic.severity.ERROR,
}
local severity_hl = {
[vim.diagnostic.severity.HINT] = 'Hint',
[vim.diagnostic.severity.INFO] = 'Info',
[vim.diagnostic.severity.WARN] = 'Warn',
[vim.diagnostic.severity.ERROR] = 'Error',
}
local diagnostics_base = {
update = { 'DiagnosticChanged', 'BufEnter' },
init = function(self)
local all_diagnostics = vim.diagnostic.get(0)
for key, severity in pairs(severities) do
self[key] = #vim
.iter(all_diagnostics)
:filter(function(d)
return d.severity == severity
end)
:totable()
end
self.counts = vim.diagnostic.count(0)
end,
}

Expand All @@ -69,19 +66,19 @@ function M.Diagnostics(is_winbar, bg)
return utils.insert(
diagnostics_base,
unpack(vim
.iter(severities_order)
.iter(diagnostics_order)
:map(function(severity)
local component = {
provider = function(self)
return string.format('%s%s ', icons[severity], self[severity])
return string.format('%s%s ', icons[severity], self.counts[severity] or 0)
end,
hl = function()
return { fg = utils.get_highlight(string.format('DiagnosticSign%s', severity_hl[severity])).fg, bg = bg }
end,
}
if is_winbar then
component.condition = function(self)
return self[severity] > 0
return (self.counts[severity] or 0) > 0
end
end
return component
Expand Down
5 changes: 5 additions & 0 deletions nvim/lua/my/lsp/icons.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@ for _, key in ipairs(vim.tbl_keys(signs)) do
signs[string.format('DiagnosticSign%s', key)] = signs[key]
end

signs[vim.diagnostic.severity.HINT] = signs.Hint
signs[vim.diagnostic.severity.INFO] = signs.Info
signs[vim.diagnostic.severity.WARN] = signs.Warn
signs[vim.diagnostic.severity.ERROR] = signs.Error

return signs

0 comments on commit 8bd2195

Please sign in to comment.