diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 17:42:05 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-05 17:42:05 +0800 |
commit | 0a11d6f52abe6f0c913c5286b2da7598caf324e0 (patch) | |
tree | 03d8f3d12304320ff0ed784f2d8abc6ce75a4d90 /script/core | |
parent | 96fbddee50795421f3476140c0cfc0dac48c71a3 (diff) | |
download | lua-language-server-0a11d6f52abe6f0c913c5286b2da7598caf324e0.zip |
`diagnostics.workspaceRate`
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/diagnostics/init.lua | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/script/core/diagnostics/init.lua b/script/core/diagnostics/init.lua index 4f5510c7..72672f14 100644 --- a/script/core/diagnostics/init.lua +++ b/script/core/diagnostics/init.lua @@ -19,6 +19,32 @@ table.sort(diagList, function (a, b) return (diagSort[a] or 0) < (diagSort[b] or 0) end) +local sleepRest = 0.0 + +---@async +local function checkSleep(uri, passed) + local speedRate = config.get(uri, 'Lua.diagnostics.workspaceRate') + if speedRate <= 0 or speedRate >= 100 then + return + end + local sleepTime = passed * (100 - speedRate) / speedRate + if sleepTime + sleepRest < 0.001 then + sleepRest = sleepRest + sleepTime + return + end + sleepRest = sleepTime + sleepRest + sleepTime = sleepRest + if sleepTime > 0.1 then + sleepTime = 0.1 + end + local clock = os.clock() + await.sleep(sleepTime) + local sleeped = os.clock() - clock + + sleepRest = sleepRest - sleeped +end + +---@async ---@param uri uri ---@param name string ---@param response async fun(result: any) @@ -63,6 +89,7 @@ local function check(uri, name, response) if passed >= 0.5 then log.warn(('Diagnostics [%s] @ [%s] takes [%.3f] sec!'):format(name, uri, passed)) end + checkSleep(uri, passed) if DIAGTIMES then DIAGTIMES[name] = (DIAGTIMES[name] or 0) + passed end |