summaryrefslogtreecommitdiff
path: root/script/provider
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-01-05 17:01:55 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-01-05 17:01:55 +0800
commit32301f8de3d832d428bf75fe44269ed121f4ab4f (patch)
treedacab9a50a96a1332d10dc2b355173a8770bc9ae /script/provider
parente6c9cf88693235171cf38581d8e1cf3334744a9c (diff)
downloadlua-language-server-32301f8de3d832d428bf75fe44269ed121f4ab4f.zip
workspaceRate
Diffstat (limited to 'script/provider')
-rw-r--r--script/provider/diagnostic.lua54
1 files changed, 28 insertions, 26 deletions
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index 031295db..09e1ea85 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -168,6 +168,28 @@ function m.syntaxErrors(uri, ast)
end
---@async
+local function checkSleep(uri)
+ local speedRate = config.get(uri, 'Lua.diagnostics.workspaceRate')
+ if speedRate <= 0 or speedRate >= 100 then
+ return
+ end
+ local currentClock = os.clock()
+ local passed = currentClock - m.diagnosticsAllClock
+ local sleepTime = passed * (100 - speedRate) / speedRate + m.sleepRest
+ m.sleepRest = 0.0
+ if sleepTime < 0.001 then
+ m.sleepRest = m.sleepRest + sleepTime
+ return
+ end
+ if sleepTime > 0.1 then
+ m.sleepRest = sleepTime - 0.1
+ sleepTime = 0.1
+ end
+ await.sleep(sleepTime)
+ m.diagnosticsAllClock = os.clock()
+end
+
+---@async
function m.doDiagnostic(uri, isScopeDiag)
if not config.get(uri, 'Lua.diagnostics.enable') then
return
@@ -236,12 +258,18 @@ function m.doDiagnostic(uri, isScopeDiag)
pushResult()
local lastPushClock = os.clock()
+ ---@async
xpcall(core, log.error, uri, function (result)
diags[#diags+1] = buildDiagnostic(uri, result)
+
if not isScopeDiag and os.clock() - lastPushClock >= 0.2 then
lastPushClock = os.clock()
pushResult()
end
+
+ if isScopeDiag then
+ checkSleep(uri)
+ end
end)
pushResult()
@@ -354,32 +382,6 @@ function m.diagnosticsScope(uri, force)
end, 'files.version', ('diagnosticsScope:' .. uri))
end
----@async
-function m.checkWorkspaceDiag(uri)
- if not await.hasID('diagnosticsScope:' .. uri) then
- return
- end
- local speedRate = config.get(uri, 'Lua.diagnostics.workspaceRate')
- if speedRate <= 0 or speedRate >= 100 then
- return
- end
- local currentClock = os.clock()
- local passed = currentClock - m.diagnosticsAllClock
- local sleepTime = passed * (100 - speedRate) / speedRate + m.sleepRest
- m.sleepRest = 0.0
- if sleepTime < 0.001 then
- m.sleepRest = m.sleepRest + sleepTime
- 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
-
ws.watch(function (ev, uri)
if ev == 'reload' then
m.diagnosticsScope(uri)