diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 20:56:34 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 20:56:34 +0800 |
commit | d99e03fd46830c31b14646f4ca6344f660059af3 (patch) | |
tree | c95b1eac2b0559aa0f43532964a1da30ac1204cf /script/provider | |
parent | e6ae2c753025ae724e2e395ee5cd4c1408527fec (diff) | |
download | lua-language-server-d99e03fd46830c31b14646f4ca6344f660059af3.zip |
smooth diagnostics
Diffstat (limited to 'script/provider')
-rw-r--r-- | script/provider/diagnostic.lua | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 9f64cb88..0e2fbfde 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -93,36 +93,34 @@ local function buildDiagnostic(uri, diag) } end -local function mergeSyntaxAndDiags(a, b) - if not a and not b then +local function mergeDiags(a, b, c) + if not a and not b and not c then return nil end - local count = 0 local t = {} - if a then - for i = 1, #a do - local severity = a[i].severity - if severity == define.DiagnosticSeverity.Hint - or severity == define.DiagnosticSeverity.Information then - t[#t+1] = a[i] - elseif count < 10000 then - count = count + 1 - t[#t+1] = a[i] - end + + local function merge(diags) + if not diags then + return end - end - if b then - for i = 1, #b do - local severity = b[i].severity + for i = 1, #diags do + local diag = diags[i] + local severity = diag.severity if severity == define.DiagnosticSeverity.Hint or severity == define.DiagnosticSeverity.Information then - t[#t+1] = b[i] - elseif count < 10000 then - count = count + 1 - t[#t+1] = b[i] + if #t > 10000 then + goto CONTINUE + end end + t[#t+1] = diag + ::CONTINUE:: end end + + merge(a) + merge(b) + merge(c) + return t end @@ -208,11 +206,13 @@ function m.doDiagnostic(uri, isScopeDiag) prog:setMessage(ws.getRelativePath(uri)) local syntax = m.syntaxErrors(uri, state) + local diags = {} + local lastDiag = m.cache[uri] local function pushResult() tracy.ZoneBeginN 'mergeSyntaxAndDiags' local _ <close> = tracy.ZoneEnd - local full = mergeSyntaxAndDiags(syntax, diags) + local full = mergeDiags(syntax, lastDiag, diags) if not full then m.clear(uri) return @@ -244,8 +244,19 @@ function m.doDiagnostic(uri, isScopeDiag) lastPushClock = os.clock() pushResult() end + end, function (checkedName) + if not lastDiag then + return + end + for i, diag in ipairs(lastDiag) do + if diag.code == checkedName then + lastDiag[i] = lastDiag[#lastDiag] + lastDiag[#lastDiag] = nil + end + end end) + lastDiag = nil pushResult() end @@ -258,7 +269,6 @@ function m.refresh(uri) if uri then await.setID('diag:' .. uri) await.sleep(0.1) - m.clearCache(uri) xpcall(m.doDiagnostic, log.error, uri) end m.diagnosticsScope(uri) |