|
293 | 293 | ---
|
294 | 294 | ---@return __statusline_section
|
295 | 295 | MiniStatusline.section_diagnostics = function(args)
|
296 |
| - -- Assumption: there are no attached clients if table |
297 |
| - -- `vim.lsp.buf_get_clients()` is empty |
298 |
| - local hasnt_attached_client = next(vim.lsp.buf_get_clients()) == nil |
299 |
| - local dont_show_lsp = MiniStatusline.is_truncated(args.trunc_width) or H.isnt_normal_buffer() or hasnt_attached_client |
300 |
| - if dont_show_lsp then return '' end |
| 296 | + _G.n_attached_lsp = H.n_attached_lsp |
| 297 | + local dont_show = MiniStatusline.is_truncated(args.trunc_width) or H.isnt_normal_buffer() or H.has_no_lsp_attached() |
| 298 | + if dont_show then return '' end |
301 | 299 |
|
302 | 300 | -- Construct string parts
|
303 | 301 | local counts = H.get_diagnostic_count()
|
@@ -426,6 +424,9 @@ H.diagnostic_levels = {
|
426 | 424 | { name = 'HINT', sign = 'H' },
|
427 | 425 | }
|
428 | 426 |
|
| 427 | +-- Count of attached LSP clients per buffer id |
| 428 | +H.n_attached_lsp = {} |
| 429 | + |
429 | 430 | -- Helper functionality =======================================================
|
430 | 431 | -- Settings -------------------------------------------------------------------
|
431 | 432 | H.setup_config = function(config)
|
@@ -470,6 +471,14 @@ H.create_autocommands = function()
|
470 | 471 |
|
471 | 472 | local set_inactive = function() vim.wo.statusline = '%!v:lua.MiniStatusline.inactive()' end
|
472 | 473 | au({ 'WinLeave', 'BufLeave' }, '*', set_inactive, 'Set inactive statusline')
|
| 474 | + |
| 475 | + if vim.fn.has('nvim-0.8') == 1 then |
| 476 | + local make_track_lsp = function(increment) |
| 477 | + return function(data) H.n_attached_lsp[data.buf] = (H.n_attached_lsp[data.buf] or 0) + increment end |
| 478 | + end |
| 479 | + au('LspAttach', '*', make_track_lsp(1), 'Track LSP clients') |
| 480 | + au('LspDetach', '*', make_track_lsp(-1), 'Track LSP clients') |
| 481 | + end |
473 | 482 | end
|
474 | 483 |
|
475 | 484 | --stylua: ignore
|
@@ -583,6 +592,10 @@ H.get_filetype_icon = function()
|
583 | 592 | return devicons.get_icon(file_name, file_ext, { default = true })
|
584 | 593 | end
|
585 | 594 |
|
| 595 | +H.has_no_lsp_attached = function() return (H.n_attached_lsp[vim.api.nvim_get_current_buf()] or 0) == 0 end |
| 596 | + |
| 597 | +if vim.fn.has('nvim-0.8') == 0 then H.has_no_lsp_attached = function() return #vim.lsp.buf_get_clients() == 0 end end |
| 598 | + |
586 | 599 | H.get_diagnostic_count = function()
|
587 | 600 | local res = {}
|
588 | 601 | for _, d in ipairs(vim.diagnostic.get(0)) do
|
|
0 commit comments