-
-
Notifications
You must be signed in to change notification settings - Fork 124
Expand file tree
/
Copy pathprovider_diagnostic.lua
More file actions
66 lines (57 loc) · 1.87 KB
/
provider_diagnostic.lua
File metadata and controls
66 lines (57 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local vim,lsp,api,diagnostic = vim,vim.lsp,vim.api,vim.diagnostic
local M = {}
-- coc diagnostic
local function get_coc_diagnostic(diag_type)
local has_info,info = pcall(vim.api.nvim_buf_get_var,0,'coc_diagnostic_info')
if not has_info then return end
if info[diag_type] > 0 then
return info[diag_type]
end
return ''
end
-- nvim-lspconfig
-- see https://github.com/neovim/nvim-lspconfig
local function get_nvim_lsp_diagnostic(diag_type)
if next(lsp.buf_get_clients(0)) == nil then return '' end
local active_clients = lsp.get_active_clients()
if active_clients then
local count = 0
for _, client in ipairs(active_clients) do
count = count + table.getn(diagnostic.get(api.nvim_get_current_buf(),{ severity = diag_type }))
end
if count ~= 0 then return count .. ' ' end
end
end
function M.get_diagnostic_error()
if vim.fn.exists('*coc#rpc#start_server') == 1 then
return get_coc_diagnostic('error')
elseif not vim.tbl_isempty(lsp.buf_get_clients(0)) then
return get_nvim_lsp_diagnostic(diagnostic.severity.ERROR)
end
return ''
end
function M.get_diagnostic_warn()
if vim.fn.exists('*coc#rpc#start_server') == 1 then
return get_coc_diagnostic('warning')
elseif not vim.tbl_isempty(lsp.buf_get_clients(0)) then
return get_nvim_lsp_diagnostic(diagnostic.severity.WARN)
end
return ''
end
function M.get_diagnostic_hint()
if vim.fn.exists('*coc#rpc#start_server') == 1 then
return get_coc_diagnostic('hint')
elseif not vim.tbl_isempty(lsp.buf_get_clients(0)) then
return get_nvim_lsp_diagnostic(diagnostic.severity.HINT)
end
return ''
end
function M.get_diagnostic_info()
if vim.fn.exists('*coc#rpc#start_server') == 1 then
return get_coc_diagnostic('information')
elseif not vim.tbl_isempty(lsp.buf_get_clients(0)) then
return get_nvim_lsp_diagnostic(diagnostic.severity.INFO)
end
return ''
end
return M