diff options
Diffstat (limited to 'script/provider/diagnostic.lua')
-rw-r--r-- | script/provider/diagnostic.lua | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 492b3048..ca4bcdb8 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -11,6 +11,7 @@ local progress = require "progress" local client = require 'client' local converter = require 'proto.converter' +---@class diagnosticProvider local m = {} m._start = false m.cache = {} @@ -139,6 +140,10 @@ function m.clear(uri) log.debug('clearDiagnostics', uri) end +function m.clearCache(uri) + m.cache[uri] = false +end + function m.clearAll() for luri in pairs(m.cache) do m.clear(luri) @@ -152,11 +157,13 @@ function m.syntaxErrors(uri, ast) local results = {} - for _, err in ipairs(ast.errs) do - if not config.get 'Lua.diagnostics.disable'[err.type:lower():gsub('_', '-')] then - results[#results+1] = buildSyntaxError(uri, err) + pcall(function () + for _, err in ipairs(ast.errs) do + if not config.get 'Lua.diagnostics.disable'[err.type:lower():gsub('_', '-')] then + results[#results+1] = buildSyntaxError(uri, err) + end end - end + end) return results end @@ -180,6 +187,7 @@ function m.diagnostics(uri, diags) end) end +---@async function m.doDiagnostic(uri) if not config.get 'Lua.diagnostics.enable' then return @@ -213,6 +221,8 @@ function m.doDiagnostic(uri) return end + local version = files.getVersion(uri) + await.setID('diag:' .. uri) local prog <close> = progress.create(lang.script.WINDOW_DIAGNOSING, 0.5) @@ -236,6 +246,7 @@ function m.doDiagnostic(uri) proto.notify('textDocument/publishDiagnostics', { uri = uri, + version = version, diagnostics = full, }) if #full > 0 then @@ -265,15 +276,17 @@ function m.refresh(uri) return end await.close('diag:' .. uri) - await.call(function () + await.call(function () ---@async await.delay() if uri then - m.doDiagnostic(uri) + m.clearCache(uri) + xpcall(m.doDiagnostic, log.error, uri) end m.diagnosticsAll() end, 'files.version') end +---@async local function askForDisable() if m.dontAskedForDisable then return @@ -332,7 +345,7 @@ function m.diagnosticsAll(force) return end await.close 'diagnosticsAll' - await.call(function () + await.call(function () ---@async await.sleep(delay) m.diagnosticsAllClock = os.clock() local clock = os.clock() @@ -347,7 +360,7 @@ function m.diagnosticsAll(force) for i, uri in ipairs(uris) do bar:setMessage(('%d/%d'):format(i, #uris)) bar:setPercentage(i / #uris * 100) - m.doDiagnostic(uri) + xpcall(m.doDiagnostic, log.error, uri) await.delay() if cancelled then log.debug('Break workspace diagnostics') @@ -375,6 +388,7 @@ function m.checkStepResult() end end +---@async function m.checkWorkspaceDiag() if not await.hasID 'diagnosticsAll' then return @@ -400,7 +414,7 @@ function m.checkWorkspaceDiag() return false end -files.watch(function (ev, uri) +files.watch(function (ev, uri) ---@async if ev == 'remove' then m.clear(uri) m.refresh(uri) @@ -410,7 +424,7 @@ files.watch(function (ev, uri) end elseif ev == 'open' then if ws.isReady() then - m.doDiagnostic(uri) + xpcall(m.doDiagnostic, log.error, uri) end elseif ev == 'close' then if files.isLibrary(uri) @@ -420,7 +434,7 @@ files.watch(function (ev, uri) end end) -await.watch(function (ev, co) +await.watch(function (ev, co) ---@async if ev == 'delay' then if m.checkStepResult then m.checkStepResult() |