summaryrefslogtreecommitdiff
path: root/script/core/diagnostics/init.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-23 16:14:54 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-11-23 16:14:54 +0800
commit2790486d9176170f879f83e363341cc33cfc41c5 (patch)
tree09193ae1a5dee26292fb0bdce518acdbdfa3541e /script/core/diagnostics/init.lua
parent1c0753f54ae77d560ae6cdb232cec8383fafce92 (diff)
downloadlua-language-server-2790486d9176170f879f83e363341cc33cfc41c5.zip
improve diagnostics sort
Diffstat (limited to 'script/core/diagnostics/init.lua')
-rw-r--r--script/core/diagnostics/init.lua22
1 files changed, 15 insertions, 7 deletions
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua
index e3f2c416..bb0489a8 100644
--- a/script/core/diagnostics/init.lua
+++ b/script/core/diagnostics/init.lua
@@ -94,20 +94,21 @@ end
---@param name string
---@param isScopeDiag boolean
---@param response async fun(result: any)
+---@return boolean
local function check(uri, name, isScopeDiag, response)
local disables = config.get(uri, 'Lua.diagnostics.disable')
if util.arrayHas(disables, name) then
- return
+ return false
end
local severity = getSeverity(uri, name)
local status = getStatus(uri, name)
if status == 'None' then
- return
+ return false
end
if status == 'Opened' and not files.isOpen(uri) then
- return
+ return false
end
local level = define.DiagnosticSeverity[severity]
@@ -140,10 +141,12 @@ local function check(uri, name, isScopeDiag, response)
if DIAGTIMES then
DIAGTIMES[name] = (DIAGTIMES[name] or 0) + passed
end
+ return true
end
local diagList
local diagCosts = {}
+local diagCount = {}
local function buildDiagList()
if not diagList then
diagList = {}
@@ -152,7 +155,9 @@ local function buildDiagList()
end
end
table.sort(diagList, function (a, b)
- return (diagCosts[a] or 0) < (diagCosts[b] or 0)
+ local time1 = (diagCosts[a] or 0) / (diagCount[a] or 1)
+ local time2 = (diagCosts[b] or 0) / (diagCount[b] or 1)
+ return time1 < time2
end)
return diagList
end
@@ -171,9 +176,12 @@ return function (uri, isScopeDiag, response, checked)
for _, name in ipairs(buildDiagList()) do
await.delay()
local clock = os.clock()
- check(uri, name, isScopeDiag, response)
- local cost = os.clock() - clock
- diagCosts[name] = (diagCosts[name] or 0) + cost
+ local suc = check(uri, name, isScopeDiag, response)
+ if suc then
+ local cost = os.clock() - clock
+ diagCosts[name] = (diagCosts[name] or 0) + cost
+ diagCount[name] = (diagCount[name] or 0) + 1
+ end
if checked then
checked(name)
end