Skip to content

Commit

Permalink
#946 use a better way
Browse files Browse the repository at this point in the history
Clear cache when `didOpen`. This avoids clearing the cache according to the situation in the diagnostic business.
  • Loading branch information
sumneko committed Apr 22, 2022
1 parent ddc9965 commit 3ef5739
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions script/provider/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ local function mergeDiags(a, b, c)
return t
end

-- enable `push`, disable `clear`
function m.clear(uri)
await.close('diag:' .. uri)
if not m.cache[uri] then
if m.cache[uri] == nil then
return
end
m.cache[uri] = nil
Expand All @@ -144,6 +145,7 @@ function m.clear(uri)
log.info('clearDiagnostics', uri)
end

-- enable `push` and `send`
function m.clearCache(uri)
m.cache[uri] = false
end
Expand Down Expand Up @@ -256,11 +258,6 @@ function m.doDiagnostic(uri, isScopeDiag)
end
end

-- always re-sent diagnostics of current file
if not isScopeDiag then
m.cache[uri] = nil
end

pushResult()

local lastPushClock = time.time()
Expand Down Expand Up @@ -435,6 +432,7 @@ files.watch(function (ev, uri) ---@async
m.refresh(uri)
elseif ev == 'open' then
if ws.isReady(uri) then
m.clearCache(uri)
xpcall(m.doDiagnostic, log.error, uri)
end
elseif ev == 'close' then
Expand Down

0 comments on commit 3ef5739

Please sign in to comment.