Skip to content
This repository was archived by the owner on Jul 6, 2021. It is now read-only.

Commit eda945d

Browse files
committed
feat: better diagnostic count
1 parent 783f389 commit eda945d

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

lua/diagnostic.lua

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,33 @@ local util = require 'diagnostic.util'
33
local M = {}
44

55
M.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

734
function 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()
69100
end
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+
71110
M.on_attach = function(_, _)
72111
-- Setup autocmd
73112
vim.api.nvim_command [[augroup DiagnosticRefresh]]

plugin/diagnostic.vim

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ if ! exists('g:diagnostic_auto_popup_while_jump')
3737
let g:diagnostic_auto_popup_while_jump = 1
3838
endif
3939

40-
40+
if ! exists('g:diagnostic_level')
41+
let g:diagnostic_level = 'Warning'
42+
endif
4143

4244

4345
let &cpo = s:save_cpo

0 commit comments

Comments
 (0)