|
79 | 79 | local get_diagnostics = { |
80 | 80 | nvim_lsp = function() |
81 | 81 | local results = {} |
82 | | - local diagnostics = vim.diagnostic.get() |
83 | | - for _, d in pairs(diagnostics) do |
84 | | - if diagnostic_is_enabled(d) then |
85 | | - if not results[d.bufnr] then results[d.bufnr] = {} end |
86 | | - table.insert(results[d.bufnr], d) |
| 82 | + |
| 83 | + -- skip buffers opened by LSP, use only loaded ones |
| 84 | + local current_buffers = vim.api.nvim_list_bufs() |
| 85 | + local loaded_buffers = {} |
| 86 | + for _, bufnr in ipairs(current_buffers) do |
| 87 | + if vim.api.nvim_buf_is_loaded(bufnr) then table.insert(loaded_buffers, bufnr) end |
| 88 | + end |
| 89 | + |
| 90 | + for _, bufnr in pairs(loaded_buffers) do |
| 91 | + local diagnostics_count = vim.diagnostic.count(bufnr) |
| 92 | + diagnostics_count = 0 |
| 93 | + + (diagnostics_count[vim.diagnostic.severity.ERROR] or 0) |
| 94 | + + (diagnostics_count[vim.diagnostic.severity.WARN] or 0) |
| 95 | + + (diagnostics_count[vim.diagnostic.severity.INFO] or 0) |
| 96 | + + (diagnostics_count[vim.diagnostic.severity.HINT] or 0) |
| 97 | + |
| 98 | + -- A safeguard to skip processing too many diagnostics altogether per given buffer |
| 99 | + if diagnostics_count < 1024 then |
| 100 | + local diagnostics = vim.diagnostic.get(bufnr) |
| 101 | + for _ = 1, #diagnostics do |
| 102 | + local d = diagnostics[_] |
| 103 | + if diagnostic_is_enabled(d) then |
| 104 | + if not results[d.bufnr] then results[d.bufnr] = {} end |
| 105 | + table.insert(results[bufnr], d) |
| 106 | + end |
| 107 | + end |
87 | 108 | end |
88 | 109 | end |
89 | 110 | return results |
|
0 commit comments