diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-11-02 15:48:00 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-11-02 15:48:00 +0800 |
commit | 5243d38793549354fc137831f3481137a882f77e (patch) | |
tree | b624421f4d52ecfc0503bf88b6f1bdcb12108447 /script-beta/provider/diagnostic.lua | |
parent | 614196b67198e3e0765a25b6b9c1b0a45624855e (diff) | |
download | lua-language-server-5243d38793549354fc137831f3481137a882f77e.zip |
后台诊断速率
Diffstat (limited to 'script-beta/provider/diagnostic.lua')
-rw-r--r-- | script-beta/provider/diagnostic.lua | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/script-beta/provider/diagnostic.lua b/script-beta/provider/diagnostic.lua index 0e80daf5..fe014b5f 100644 --- a/script-beta/provider/diagnostic.lua +++ b/script-beta/provider/diagnostic.lua @@ -11,6 +11,7 @@ local ws = require 'workspace' local m = {} m._start = false m.cache = {} +m.sleepRest = 0.0 local function concat(t, sep) if type(t) ~= 'table' then @@ -203,10 +204,11 @@ function m.diagnosticsAll() await.close 'diagnosticsAll' await.call(function () await.sleep(delay) + m.diagnosticsAllClock = os.clock() local clock = os.clock() for uri in files.eachFile() do - await.delay() m.doDiagnostic(uri) + await.delay() end log.debug('全文诊断耗时:', os.clock() - clock) end, 'files.version', 'diagnosticsAll') @@ -217,6 +219,30 @@ function m.start() m.diagnosticsAll() end +function m.onDelay() + if not await.hasID 'diagnosticsAll' then + return + end + local currentClock = os.clock() + local passed = currentClock - m.diagnosticsAllClock + local speedRate = config.config.diagnostics.workspaceRate + if speedRate <= 0 or speedRate >= 100 then + return + end + local sleepTime = passed * (100 - speedRate) / speedRate + m.sleepRest + m.sleepRest = 0.0 + if sleepTime < 0.001 then + return + end + if sleepTime > 0.1 then + m.sleepRest = sleepTime - 0.1 + sleepTime = 0.1 + end + await.sleep(sleepTime) + m.diagnosticsAllClock = os.clock() + return false +end + files.watch(function (ev, uri) if ev == 'remove' then m.clear(uri) @@ -227,4 +253,10 @@ files.watch(function (ev, uri) end end) +await.watch(function (ev, co) + if ev == 'delay' then + return m.onDelay() + end +end) + return m |