diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-02 20:51:42 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-02 20:51:42 +0800 |
commit | d2555c83e1e4338f52a740cbd163fed043219888 (patch) | |
tree | 1fa03cf6ae92594d2fbb7cf9ce11ad2e40612da8 /script-beta | |
parent | ededf909f340f582195ba2f88b85787fa3142be1 (diff) | |
download | lua-language-server-d2555c83e1e4338f52a740cbd163fed043219888.zip |
分步给出诊断结果
Diffstat (limited to 'script-beta')
-rw-r--r-- | script-beta/core/diagnostics/init.lua | 28 | ||||
-rw-r--r-- | script-beta/provider/diagnostic.lua | 83 |
2 files changed, 74 insertions, 37 deletions
diff --git a/script-beta/core/diagnostics/init.lua b/script-beta/core/diagnostics/init.lua index ab5c0a71..b00e64ed 100644 --- a/script-beta/core/diagnostics/init.lua +++ b/script-beta/core/diagnostics/init.lua @@ -3,6 +3,19 @@ local define = require 'proto.define' local config = require 'config' local await = require 'await' +-- 把耗时最长的诊断放到最后面 +local diagLevel = { + ['redundant-parameter'] = 100, +} + +local diagList = {} +for k in pairs(define.DiagnosticDefaultSeverity) do + diagList[#diagList+1] = k +end +table.sort(diagList, function (a, b) + return (diagLevel[a] or 0) < (diagLevel[b] or 0) +end) + local function check(uri, name, level, results) if config.config.diagnostics.disable[name] then return @@ -21,23 +34,18 @@ local function check(uri, name, level, results) end end -return function (uri) +return function (uri, response) local vm = require 'vm' local ast = files.getAst(uri) if not ast then return nil end - local results = {} - for name, level in pairs(define.DiagnosticDefaultSeverity) do + for _, name in ipairs(diagList) do + local level = define.DiagnosticDefaultSeverity[name] await.delay() - vm.setSearchLevel(0) + local results = {} check(uri, name, level, results) + response(results) end - - if #results == 0 then - return nil - end - - return results end diff --git a/script-beta/provider/diagnostic.lua b/script-beta/provider/diagnostic.lua index b33bd933..c53f4635 100644 --- a/script-beta/provider/diagnostic.lua +++ b/script-beta/provider/diagnostic.lua @@ -133,22 +133,19 @@ function m.syntaxErrors(uri, ast) return results end -function m.diagnostics(uri) +function m.diagnostics(uri, diags) if not m._start then - return m.cache[uri] - end - - local diags = core(uri) - if not diags then - return nil - end - - local results = {} - for _, diag in ipairs(diags) do - results[#results+1] = buildDiagnostic(uri, diag) + return end - return results + core(uri, function (results) + if #results == 0 then + return + end + for i = 1, #results do + diags[#diags+1] = buildDiagnostic(uri, results[i]) + end + end) end function m.doDiagnostic(uri) @@ -163,22 +160,45 @@ function m.doDiagnostic(uri) end local syntax = m.syntaxErrors(uri, ast) - local diagnostics = m.diagnostics(uri) - local full = merge(syntax, diagnostics) - if not full then - m.clear(uri) - return + local diags = {} + if syntax then + for _, err in ipairs(syntax) do + diags[#diags+1] = err + end end - if util.equal(m.cache[uri], full) then - return + local function pushResult() + local full = merge(syntax, diags) + if not full then + m.clear(uri) + return + end + + if util.equal(m.cache, full) then + return + end + m.cache[uri] = full + + proto.notify('textDocument/publishDiagnostics', { + uri = files.getOriginUri(uri), + diagnostics = full, + }) end - m.cache[uri] = full - proto.notify('textDocument/publishDiagnostics', { - uri = files.getOriginUri(uri), - diagnostics = full, - }) + if await.hasID 'diagnosticsAll' then + m.checkStepResult = nil + else + local clock = os.clock() + m.checkStepResult = function () + if os.clock() - clock >= 0.2 then + pushResult() + clock = os.clock() + end + end + end + + m.diagnostics(uri, diags) + pushResult() end function m.refresh(uri) @@ -219,7 +239,13 @@ function m.start() m.diagnosticsAll() end -function m.onDelay() +function m.checkStepResult() + if await.hasID 'diagnosticsAll' then + return + end +end + +function m.checkWorkspaceDiag() if not await.hasID 'diagnosticsAll' then return end @@ -255,7 +281,10 @@ end) await.watch(function (ev, co) if ev == 'delay' then - return m.onDelay() + if m.checkStepResult then + m.checkStepResult() + end + return m.checkWorkspaceDiag() end end) |