summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-30 17:41:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-30 17:41:44 +0800
commita0c905ba6de413df0fc754d638db6431a203b330 (patch)
treeab3be6f9d92b33c9e2ce507f4652580ea6bd986e /script
parent3a21b34bb31c8988bff6b636bdbf506db373d564 (diff)
downloadlua-language-server-a0c905ba6de413df0fc754d638db6431a203b330.zip
flush cache after 5 min
Diffstat (limited to 'script')
-rw-r--r--script/service/service.lua28
-rw-r--r--script/workspace/workspace.lua4
2 files changed, 31 insertions, 1 deletions
diff --git a/script/service/service.lua b/script/service/service.lua
index 20e07980..c7ca15bf 100644
--- a/script/service/service.lua
+++ b/script/service/service.lua
@@ -7,6 +7,7 @@ local vm = require 'vm'
local util = require 'utility'
local files = require 'files'
local lang = require 'language'
+local ws = require 'workspace'
local m = {}
m.type = 'service'
@@ -140,20 +141,40 @@ function m.startTimer()
pub.step()
if await.step() then
m.working = true
+ m.sleeping = false
goto CONTINUE
end
- m.working = false
+ if m.working then
+ m.working = false
+ m.idleClock = os.clock()
+ end
thread.sleep(0.001)
::CONTINUE::
timer.update()
end
end
+function m.checkSleep()
+ timer.loop(10, function ()
+ if not m.working and not m.sleeping and os.clock() - m.idleClock >= 300 then
+ m.sleeping = true
+ files.flushCache()
+ vm.flushCache()
+ ws.flushCache()
+ collectgarbage()
+ collectgarbage()
+ end
+ end)
+end
+
function m.reportStatus()
+ local lastInfo
timer.loop(0.1, function ()
local info = {}
if m.working then
info.text = '$(loading~spin)Lua'
+ elseif m.sleeping then
+ info.text = "💤Lua"
else
info.text = '😺Lua'
end
@@ -162,6 +183,10 @@ function m.reportStatus()
max = files.fileCount,
mem = collectgarbage('count') / 1000,
})
+ if util.equal(lastInfo, info) then
+ return
+ end
+ lastInfo = info
proto.notify('$/status/report', info)
end)()
end
@@ -183,6 +208,7 @@ function m.start()
pub.recruitBraves(4)
proto.listen()
m.report()
+ m.checkSleep()
m.reportStatus()
m.testVersion()
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index d0676b30..edde3ab9 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -423,6 +423,10 @@ function m.getCache(name)
return m.cache[name]
end
+function m.flushCache()
+ m.cache = {}
+end
+
function m.reload()
await.call(m.awaitReload)
end