local if_nil = vim.F.if_nil
local M = {}
M.severity = {
ERROR = 1,
WARN = 2,
INFO = 3,
HINT = 4,
}
vim.tbl_add_reverse_lookup(M.severity)
-- Mappings from qflist/loclist error types to severities
M.severity.E = M.severity.ERROR
M.severity.W = M.severity.WARN
M.severity.I = M.severity.INFO
M.severity.N = M.severity.HINT
local global_diagnostic_options = {
signs = true,
underline = true,
virtual_text = true,
float = true,
update_in_insert = false,
severity_sort = false,
}
M.handlers = setmetatable({}, {
__newindex = function(t, name, handler)
vim.validate { handler = {handler, "t" } }
rawset(t, name, handler)
if not global_diagnostic_options[name] then
global_diagnostic_options[name] = true
end
end,
})
-- Metatable that automatically creates an empty table when assigning to a missing key
local bufnr_and_namespace_cacher_mt = {
__index = function(t, bufnr)
assert(bufnr > 0, "Invalid buffer number")
t[bufnr] = {}
return t[bufnr]
end,
}
local diagnostic_cache = setmetatable({}, {
__index = function(t, bufnr)
assert(bufnr > 0, "Invalid buffer number")
vim.api.nvim_buf_attach(bufnr, false, {
on_detach = function()
rawset(t, bufnr, nil) -- clear cache
end
})
t[bufnr] = {}
return t[bufnr]
end,
})
local diagnostic_cache_extmarks = setmetatable({}, bufnr_and_namespace_cacher_mt)
local diagnostic_attached_buffers = {}
local diagnostic_disabled = {}
local bufs_waiting_to_update = setmetatable({}, bufnr_and_namespace_cacher_mt)
loc
|