summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2022-01-22 05:48:53 +0800
committersumneko <sumneko@hotmail.com>2022-01-22 05:48:53 +0800
commit37d33caad5eca02ffa3ac0608ccfe13468bdd22e (patch)
treea481bde0654d8dcbdd8c54c000296e52f7ba29fb /script
parent877306a927b098e25853f38ea792dd5ee663bbfd (diff)
downloadlua-language-server-37d33caad5eca02ffa3ac0608ccfe13468bdd22e.zip
use async loadFile
Diffstat (limited to 'script')
-rw-r--r--script/brave/work.lua4
-rw-r--r--script/pub/report.lua1
-rw-r--r--script/workspace/loading.lua32
3 files changed, 23 insertions, 14 deletions
diff --git a/script/brave/work.lua b/script/brave/work.lua
index 6307c777..49c90f83 100644
--- a/script/brave/work.lua
+++ b/script/brave/work.lua
@@ -24,3 +24,7 @@ brave.on('timer', function (time)
brave.push('wakeup')
end
end)
+
+brave.on('loadFile', function (path)
+ return util.loadFile(path)
+end)
diff --git a/script/pub/report.lua b/script/pub/report.lua
index a695429e..bce5309b 100644
--- a/script/pub/report.lua
+++ b/script/pub/report.lua
@@ -1,5 +1,6 @@
local pub = require 'pub.pub'
local await = require 'await'
+local util = require 'utility'
pub.on('log', function (params, brave)
log.raw(brave.id, params.level, params.msg, params.src, params.line, params.clock)
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua
index 1fcd0d77..a54f4504 100644
--- a/script/workspace/loading.lua
+++ b/script/workspace/loading.lua
@@ -6,6 +6,7 @@ local config = require 'config.config'
local client = require 'client'
local util = require 'utility'
local furi = require 'file-uri'
+local pub = require 'pub'
---@class workspace.loading
---@field scp scope
@@ -75,14 +76,18 @@ function mt:loadFile(uri, libraryUri)
end
self.max = self.max + 1
self:update()
+ ---@async
self._stash[#self._stash+1] = function ()
- self.read = self.read + 1
if files.getFile(uri) then
+ self.read = self.read + 1
+ self:update()
+ self._cache[uri] = true
files.addRef(uri)
log.info(('Skip loaded file: %s'):format(uri))
return
end
- local content = util.loadFile(furi.decode(uri))
+ local content = pub.awaitTask('loadFile', furi.decode(uri))
+ self.read = self.read + 1
self:update()
if not content then
return
@@ -102,14 +107,18 @@ function mt:loadFile(uri, libraryUri)
elseif files.isDll(uri) then
self.max = self.max + 1
self:update()
+ ---@async
self._stash[#self._stash+1] = function ()
- self.read = self.read + 1
if files.getFile(uri) then
+ self.read = self.read + 1
+ self:update()
+ self._cache[uri] = true
files.addRef(uri)
log.info(('Skip loaded file: %s'):format(uri))
return
end
- local content = util.loadFile(furi.decode(uri))
+ local content = pub.awaitTask('loadFile', furi.decode(uri))
+ self.read = self.read + 1
self:update()
if not content then
return
@@ -129,28 +138,23 @@ function mt:loadFile(uri, libraryUri)
await.delay()
end
----@async
function mt:loadStashed(max)
for _ = 1, max do
local loader = table.remove(self._stash)
if not loader then
- return false
+ return
end
- loader()
- await.delay()
+ await.call(loader)
end
- return true
end
---@async
function mt:loadAll()
- while true do
+ while self.read < self.max do
log.info(('Loaded %d/%d files'):format(self.read, self.max))
- local suc = self:loadStashed(10)
+ self:loadStashed(100)
self:update()
- if not suc then
- break
- end
+ await.sleep(0.1)
end
log.info('Loaded finish.')
end