Skip to content

Commit dde7916

Browse files
committed
fix diagnostics not getting cleared
1 parent d3a019c commit dde7916

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

language_server/editor_helper.lua

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,11 @@ function META:Recompile(path, lol, diagnostics)
328328
end
329329

330330
for name, data in pairs(diagnostics) do
331-
if #data > 0 then self:OnDiagnostics(name, data) end
331+
if #data > 0 then
332+
self:OnDiagnostics(name, data)
333+
else
334+
self:OnClearDiagnostics(name)
335+
end
332336
end
333337

334338
return true
@@ -340,6 +344,8 @@ end
340344

341345
function META:OnDiagnostics(name, data) end
342346

347+
function META:OnClearDiagnostics(name) end
348+
343349
function META:OnResponse(response) end
344350

345351
function META:Initialize()

language_server/lsp.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@ editor_helper:SetConfigFunction(function(path)
104104
end
105105
end)
106106

107+
function editor_helper:OnClearDiagnostics(path)
108+
lsp.Call(
109+
{
110+
method = "textDocument/publishDiagnostics",
111+
params = {
112+
uri = to_lsp_path(path),
113+
diagnostics = {},
114+
},
115+
}
116+
)
117+
end
118+
107119
function editor_helper:OnDiagnostics(path, data)
108120
local DiagnosticSeverity = {
109121
error = 1,

test/tests/editor_helper.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,4 +400,27 @@ loadstring("local x = 'hello'")
400400
end
401401
end
402402

403+
do
404+
-- Test that diagnostics are properly cleared when errors are fixed
405+
local helper = EditorHelper.New()
406+
helper:Initialize()
407+
local diagnostics_calls = {}
408+
409+
function helper:OnDiagnostics(name, data)
410+
table.insert(diagnostics_calls, {
411+
name = name,
412+
data = data,
413+
count = #data,
414+
})
415+
end
416+
417+
helper:OpenFile(path, [[locwal]])
418+
helper:Recompile(path)
419+
assert(#diagnostics_calls > 0)
420+
diagnostics_calls = {} -- reset
421+
helper:UpdateFile(path, [[local a = 1]])
422+
helper:Recompile(path)
423+
assert(#diagnostics_calls == 0)
424+
end
425+
403426
_G.TEST = false

0 commit comments

Comments
 (0)