From 6c4a1ae9bdfcf146899993974444436a56ba53fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 23 Jun 2022 15:15:26 +0800 Subject: `FIX` diagnostics flash when opening a file --- script/provider/diagnostic.lua | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'script/provider') diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 4c94c952..8085713e 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -159,11 +159,6 @@ function m.clear(uri, force) log.info('clearDiagnostics', uri) end --- enable `push` and `send` -function m.clearCache(uri) - m.cache[uri] = false -end - function m.clearCacheExcept(uris) local excepts = {} for _, uri in ipairs(uris) do @@ -330,6 +325,23 @@ function m.doDiagnostic(uri, isScopeDiag) pushResult() end +---@param uri uri +function m.resendDiagnostic(uri) + local full = m.cache[uri] + if not full then + return + end + + local version = files.getVersion(uri) + + proto.notify('textDocument/publishDiagnostics', { + uri = uri, + version = version, + diagnostics = full, + }) + log.debug('publishDiagnostics', uri, #full) +end + ---@async ---@return table|nil result ---@return boolean? unchanged @@ -565,7 +577,7 @@ files.watch(function (ev, uri) ---@async m.refresh(uri) elseif ev == 'open' then if ws.isReady(uri) then - m.clearCache(uri) + m.resendDiagnostic(uri) xpcall(m.doDiagnostic, log.error, uri) end elseif ev == 'close' then -- cgit v1.2.3