diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-12 17:19:03 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-12 17:19:03 +0800 |
commit | ac9e09ffb7e0dddf7e48725ce59733c53a7443b3 (patch) | |
tree | 8635af9b4e8b8b770bbb565eddeb48494dfbb5f3 /script/service/service.lua | |
parent | d066720039568bab0126bc058faf23588500562a (diff) | |
download | lua-language-server-ac9e09ffb7e0dddf7e48725ce59733c53a7443b3.zip |
improve completion speed
Diffstat (limited to 'script/service/service.lua')
-rw-r--r-- | script/service/service.lua | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/script/service/service.lua b/script/service/service.lua index ea6ff1e5..627388d1 100644 --- a/script/service/service.lua +++ b/script/service/service.lua @@ -141,23 +141,46 @@ function m.report() t:onTimer() end -function m.startTimer() +function m.eventLoop() pub.task('timer', 1) - while true do - pub.step(not m.workingClock) - if await.step() then - m.sleeping = false - if not m.workingClock then - m.workingClock = time.monotonic() - end - else - if m.workingClock then - m.workingClock = nil - m.idleClock = time.monotonic() - m.reportStatus() + + local function doSomething() + pub.step(false) + if not await.step() then + return false + end + m.sleeping = false + if not m.workingClock then + m.workingClock = time.monotonic() + end + return true + end + + local function sleep() + if m.workingClock then + m.workingClock = nil + m.idleClock = time.monotonic() + m.reportStatus() + end + for _ = 1, 10 do + thread.sleep(0.1) + if doSomething() then + return end end + pub.step(true) + end + + while true do + if doSomething() then + goto CONTINUE + end timer.update() + if doSomething() then + goto CONTINUE + end + sleep() + ::CONTINUE:: end end @@ -234,7 +257,7 @@ function m.start() require 'provider' - m.startTimer() + m.eventLoop() end return m |