@@ -3,6 +3,33 @@ local util = require 'diagnostic.util'
33local M = {}
44
55M .bufferDiagnostic = {}
6+ local diagnosticTable = {}
7+
8+ local remove_diagnostics = function (diagnostics )
9+ -- Remove Index
10+ local remove = {}
11+ local level = vim .lsp .protocol .DiagnosticSeverity [vim .api .nvim_get_var (' diagnostic_level' )]
12+ for idx , diagnostic in ipairs (diagnostics ) do
13+ if diagnostic .severity > level then
14+ remove [idx ] = true
15+ else
16+ remove [idx ] = false
17+ end
18+ end
19+ for i = # diagnostics , 1 , - 1 do
20+ if remove [i ] then
21+ table.remove (diagnostics , i )
22+ end
23+ end
24+ return diagnostics
25+ end
26+
27+ local get_diagnostics_count = function (diagnostics , bufnr )
28+ diagnosticTable .bufnr = {0 , 0 , 0 , 0 }
29+ for idx , diagnostic in pairs (diagnostics ) do
30+ diagnosticTable .bufnr [diagnostic .severity ] = diagnosticTable .bufnr [diagnostic .severity ] + 1
31+ end
32+ end
633
734function M .modifyCallback ()
835 local callback = ' textDocument/publishDiagnostics'
@@ -16,6 +43,10 @@ function M.modifyCallback()
1643 vim .lsp .err_message (" LSP.publishDiagnostics: Couldn't find buffer for " , uri )
1744 return
1845 end
46+ get_diagnostics_count (result .diagnostics , bufnr )
47+ if vim .api .nvim_get_var (' diagnostic_level' ) ~= nil then
48+ result .diagnostics = remove_diagnostics (result .diagnostics )
49+ end
1950 M .bufferDiagnostic [bufnr ] = result
2051 if vim .api .nvim_get_var (' diagnostic_insert_delay' ) == 1 then
2152 if vim .api .nvim_get_mode ()[' mode' ] == " i" or vim .api .nvim_get_mode ()[' mode' ] == " ic" then
@@ -68,6 +99,14 @@ function M.on_InsertLeave()
6899 M .refresh_diagnostics ()
69100end
70101
102+ function M .getDiagnosticCount (level , bufnr )
103+ if diagnosticTable .bufnr == nil then
104+ return 0
105+ end
106+ return diagnosticTable .bufnr [level ]
107+ end
108+
109+
71110M .on_attach = function (_ , _ )
72111 -- Setup autocmd
73112 vim .api .nvim_command [[ augroup DiagnosticRefresh]]
0 commit comments