Skip to content

Feat: use vim.diagnostic.status if available #1450

@aktau

Description

@aktau

Requested feature

Neovim just merged neovim/neovim#33723. The vim.diagnostic.status() function m ay be useful. It seems to render the same way as the current nvim_diagnostic, though that appears to be more flexible:

nvim_diagnostic = function()
local count
if vim.diagnostic.count ~= nil then -- neovim >= 0.10.0
count = vim.diagnostic.count(0)
return count[vim.diagnostic.severity.ERROR] or 0,
count[vim.diagnostic.severity.WARN] or 0,
count[vim.diagnostic.severity.INFO] or 0,
count[vim.diagnostic.severity.HINT] or 0
end
-- fallback
local diagnostics = vim.diagnostic.get(0)
count = { 0, 0, 0, 0 }
for _, diagnostic in ipairs(diagnostics) do
count[diagnostic.severity] = count[diagnostic.severity] + 1
end
return count[vim.diagnostic.severity.ERROR],
count[vim.diagnostic.severity.WARN],
count[vim.diagnostic.severity.INFO],
count[vim.diagnostic.severity.HINT]
end,
.

Also interesting is that this change seems to force/issue a redraw command when diagnostics change. If lualine also registers that, it would improve performance to no longer do it.

Motivation

It may simplify code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    new featureNew feature or feature request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions