Skip to content

Commit e9edc00

Browse files
authored
feat!: ignore disabled diagnostics (#1148)
BREAKING CHANGE: lua `vim` global warnings are no longer ignored by neo-tree, this can be configured in the lsp config
1 parent 2d89ca9 commit e9edc00

File tree

1 file changed

+48
-21
lines changed

1 file changed

+48
-21
lines changed

lua/neo-tree/utils/init.lua

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -214,39 +214,66 @@ M.human_size = function (size)
214214
return human
215215
end
216216

217-
---Gets diagnostic severity counts for all files
218-
---@return table table { file_path = { Error = int, Warning = int, Information = int, Hint = int, Unknown = int } }
217+
---Gets non-zero diagnostics counts for each open file and each ancestor directory.
218+
---severity_number and severity_string refer to the highest severity with
219+
---non-zero diagnostics count.
220+
---Entry is nil if all counts are 0
221+
---@return table table
222+
---{ [file_path] = {
223+
--- severity_number = int,
224+
--- severity_string = string,
225+
--- Error = int or nil,
226+
--- Warn = int or nil,
227+
--- Info = int or nil
228+
--- Hint = int or nil,
229+
--- } or nil }
219230
M.get_diagnostic_counts = function()
220-
local d = vim.diagnostic.get()
221231
local lookup = {}
222-
for _, diag in ipairs(d) do
223-
if diag.source == "Lua Diagnostics." and diag.message == "Undefined global `vim`." then
224-
-- ignore this diagnostic
225-
else
226-
local success, file_name = pcall(vim.api.nvim_buf_get_name, diag.bufnr)
227-
if success then
228-
local sev = diag_severity_to_string(diag.severity)
229-
if sev then
230-
local entry = lookup[file_name] or { severity_number = 4 }
231-
entry[sev] = (entry[sev] or 0) + 1
232-
entry.severity_number = math.min(entry.severity_number, diag.severity)
233-
entry.severity_string = diag_severity_to_string(entry.severity_number)
234-
lookup[file_name] = entry
232+
233+
for ns, _ in pairs(vim.diagnostic.get_namespaces()) do
234+
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
235+
local success, file_name = pcall(vim.api.nvim_buf_get_name, bufnr)
236+
if success and not vim.diagnostic.is_disabled(bufnr, ns) then
237+
for severity, _ in ipairs(vim.diagnostic.severity) do
238+
local diagnostics = vim.diagnostic.get(bufnr, { namespace = ns, severity = severity })
239+
240+
if #diagnostics > 0 then
241+
local severity_string = diag_severity_to_string(severity)
242+
if lookup[file_name] == nil then
243+
lookup[file_name] = {
244+
severity_number = severity,
245+
severity_string = severity_string,
246+
}
247+
end
248+
if severity_string ~= nil then
249+
lookup[file_name][severity_string] = #diagnostics
250+
end
251+
end
235252
end
236253
end
237254
end
238255
end
239256

240-
for file_name, entry in pairs(lookup) do
257+
for file_name, file_entry in pairs(lookup) do
241258
-- Now bubble this status up to the parent directories
242259
local parts = M.split(file_name, M.path_separator)
243260
table.remove(parts) -- pop the last part so we don't override the file's status
244261
M.reduce(parts, "", function(acc, part)
245262
local path = (M.is_windows and acc == "") and part or M.path_join(acc, part)
246-
local path_entry = lookup[path] or { severity_number = 4 }
247-
path_entry.severity_number = math.min(path_entry.severity_number, entry.severity_number)
248-
path_entry.severity_string = diag_severity_to_string(path_entry.severity_number)
249-
lookup[path] = path_entry
263+
264+
if file_entry.severity_number then
265+
if not lookup[path] then
266+
lookup[path] = {
267+
severity_number = file_entry.severity_number,
268+
severity_string = file_entry.severity_string,
269+
}
270+
else -- lookup[path].severity_number ~= nil
271+
local min_severity = math.min(lookup[path].severity_number, file_entry.severity_number)
272+
lookup[path].severity_number = min_severity
273+
lookup[path].severity_string = diag_severity_to_string(min_severity)
274+
end
275+
end
276+
250277
return path
251278
end)
252279
end

0 commit comments

Comments
 (0)