summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-02 11:36:45 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-02 11:36:45 +0800
commit33beca3671744d7d7add8310774a5b01c3392188 (patch)
tree2d2cb8f05084ce9aeacab2ba5a5b805ab9c67798 /script-beta
parentd34679f9d8a92ccb0f4ad98b420a9e6a0340711a (diff)
downloadlua-language-server-33beca3671744d7d7add8310774a5b01c3392188.zip
后台cpu消耗
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/config.lua3
-rw-r--r--script-beta/service/service.lua11
2 files changed, 14 insertions, 0 deletions
diff --git a/script-beta/config.lua b/script-beta/config.lua
index 99f701fd..d12107cc 100644
--- a/script-beta/config.lua
+++ b/script-beta/config.lua
@@ -149,6 +149,9 @@ local ConfigTemplate = {
enable = {false, Boolean},
path = {'.vscode/lua-plugin/*.lua', String},
},
+ misc = {
+ backGroundCPU = {10, Integer},
+ }
}
local OtherTemplate = {
diff --git a/script-beta/service/service.lua b/script-beta/service/service.lua
index 11cc7b19..3e912cb7 100644
--- a/script-beta/service/service.lua
+++ b/script-beta/service/service.lua
@@ -4,6 +4,7 @@ local await = require 'await'
local timer = require 'timer'
local proto = require 'proto'
local vm = require 'vm'
+local config = require 'config'
local m = {}
m.type = 'service'
@@ -133,13 +134,23 @@ function m.report()
end
function m.startTimer()
+ local clock = os.clock()
while true do
::CONTINUE::
pub.step()
if await.step() then
+ local passed = os.clock() - clock
+ local cpu = config.config.misc.backGroundCPU
+ if cpu >= 1 and cpu < 100 then
+ local sleepRate = (100 - cpu) / cpu
+ local extraSleep = math.min(passed * sleepRate, 0.1)
+ thread.sleep(extraSleep)
+ end
+ clock = os.clock()
goto CONTINUE
end
thread.sleep(0.001)
+ clock = os.clock()
timer.update()
end
end