From 6a40b530539d2209f7dc0492f3681c8c126647ad Mon Sep 17 00:00:00 2001 From: Oskar Meyenburg <135001586+oskarmeyenburg@users.noreply.github.com> Date: Mon, 8 Jul 2024 06:50:09 +0200 Subject: [PATCH] Use vim.diagnostic.count instead of get (Feat #1239) (#1268) --- lua/lualine/components/diagnostics/sources.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/lualine/components/diagnostics/sources.lua b/lua/lualine/components/diagnostics/sources.lua index c0ef78c7d..48fdd2164 100644 --- a/lua/lualine/components/diagnostics/sources.lua +++ b/lua/lualine/components/diagnostics/sources.lua @@ -33,8 +33,19 @@ M.sources = { workspace_diag(diag_severity.HINT) end, 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) - local count = { 0, 0, 0, 0 } + count = { 0, 0, 0, 0 } for _, diagnostic in ipairs(diagnostics) do count[diagnostic.severity] = count[diagnostic.severity] + 1 end