@@ -299,10 +299,11 @@ MiniStatusline.section_diagnostics = function(args)
299
299
local dont_show_lsp = MiniStatusline .is_truncated (args .trunc_width ) or H .isnt_normal_buffer () or hasnt_attached_client
300
300
if dont_show_lsp then return ' ' end
301
301
302
- -- Construct diagnostic info using predefined order
303
- local t = {}
302
+ -- Construct string parts
303
+ local counts = H .get_diagnostic_count ()
304
+ local severity , t = vim .diagnostic .severity , {}
304
305
for _ , level in ipairs (H .diagnostic_levels ) do
305
- local n = H . get_diagnostic_count ( level .id )
306
+ local n = counts [ severity [ level .name ]] or 0
306
307
-- Add level info only if diagnostic is present
307
308
if n > 0 then table.insert (t , string.format (' %s%s' , level .sign , n )) end
308
309
end
@@ -419,10 +420,10 @@ H.default_config = vim.deepcopy(MiniStatusline.config)
419
420
420
421
-- Showed diagnostic levels
421
422
H .diagnostic_levels = {
422
- { id = vim . diagnostic . severity . ERROR , sign = ' E' },
423
- { id = vim . diagnostic . severity . WARN , sign = ' W' },
424
- { id = vim . diagnostic . severity . INFO , sign = ' I' },
425
- { id = vim . diagnostic . severity . HINT , sign = ' H' },
423
+ { name = ' ERROR' , sign = ' E' },
424
+ { name = ' WARN' , sign = ' W' },
425
+ { name = ' INFO' , sign = ' I' },
426
+ { name = ' HINT' , sign = ' H' },
426
427
}
427
428
428
429
-- Helper functionality =======================================================
@@ -582,6 +583,14 @@ H.get_filetype_icon = function()
582
583
return devicons .get_icon (file_name , file_ext , { default = true })
583
584
end
584
585
585
- H .get_diagnostic_count = function (id ) return # vim .diagnostic .get (0 , { severity = id }) end
586
+ H .get_diagnostic_count = function ()
587
+ local res = {}
588
+ for _ , d in ipairs (vim .diagnostic .get (0 )) do
589
+ res [d .severity ] = (res [d .severity ] or 0 ) + 1
590
+ end
591
+ return res
592
+ end
593
+
594
+ if vim .fn .has (' nvim-0.10' ) == 1 then H .get_diagnostic_count = function () return vim .diagnostic .count (0 ) end end
586
595
587
596
return MiniStatusline
0 commit comments