Skip to content

Commit 1a1c015

Browse files
authored
fix: use diagnostic namespace instead of source to clear cache (#117)
1 parent 8ea688b commit 1a1c015

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lua/tiny-inline-diagnostic/diagnostic.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,20 @@ local function update_diagnostics_cache(opts, bufnr, diagnostics)
146146
-- Do the upfront work of filtering and sorting
147147
diagnostics = filter_by_severity(opts, diagnostics)
148148

149-
-- Find the sources of the incoming diagnostics.
150-
-- It's almost always a single source, but you never know.
151-
local sources = {}
149+
-- Find the namespaces of the incoming diagnostics.
150+
-- Use the namespace and not the source because the event is triggered per namespace,
151+
-- while the source field can be unreliable (e.g. Deno LSP seems to switch between
152+
-- deno and deno-ts).
153+
local namespaces = {}
152154
for _, diag in ipairs(diagnostics) do
153-
if not vim.tbl_contains(sources, diag.source) then
154-
table.insert(sources, diag.source)
155+
if not vim.tbl_contains(namespaces, diag.namespace) then
156+
table.insert(namespaces, diag.namespace)
155157
end
156158
end
157159

158160
-- Clear the diagnostics that are from the incoming source
159161
diag_buf = vim.tbl_filter(function(diag)
160-
return not vim.tbl_contains(sources, diag.source)
162+
return not vim.tbl_contains(namespaces, diag.namespace)
161163
end, diag_buf)
162164

163165
-- Insert and sort the results

0 commit comments

Comments
 (0)