diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-21 17:34:46 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-21 17:34:46 +0800 |
commit | 4d538055a120ff39fe40e9c73bb40df5645c50e4 (patch) | |
tree | 3ac853dbc3924f0096381b9495a2695a763ac4d7 /script/workspace | |
parent | 3778e5eeb3ffe35e5a5f70700635a90970a2ee40 (diff) | |
download | lua-language-server-4d538055a120ff39fe40e9c73bb40df5645c50e4.zip |
update
Diffstat (limited to 'script/workspace')
-rw-r--r-- | script/workspace/loading.lua | 66 |
1 files changed, 44 insertions, 22 deletions
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua index 19fe0728..8091cadf 100644 --- a/script/workspace/loading.lua +++ b/script/workspace/loading.lua @@ -13,6 +13,7 @@ local furi = require 'file-uri' ---@field _stash function[] ---@field _refs uri[] ---@field _cache table<uri, boolean> +---@field _removed boolean local mt = {} mt.__index = mt @@ -21,6 +22,10 @@ mt.read = 0 mt.max = 0 mt.preload = 0 +function mt:__close() + self:remove() +end + function mt:update() self._bar:setMessage(('%d/%d'):format(self.read, self.max)) self._bar:setPercentage(self.read / self.max * 100.0) @@ -114,46 +119,50 @@ function mt:loadFile(uri, libraryUri) await.delay() end -function mt:loadStashed() - self:update() - if self._loadLock then - return - end - self._loadLock = true - ---@async - await.call(function () - while true do - local loader = table.remove(self._stash) - if not loader then - break - end - loader() - await.delay() +---@async +function mt:loadStashed(max) + for _ = 1, max do + local loader = table.remove(self._stash) + if not loader then + return false end - self._loadLock = false - end) + loader() + await.delay() + end + return true end ---@async function mt:loadAll() - while self.read < self.max do + while true do log.info(('Loaded %d/%d files'):format(self.read, self.max)) - self:loadStashed() - await.sleep(0.1) + local suc = self:loadStashed(10) + self:update() + if not suc then + break + end end + log.info('Loaded finish.') end function mt:remove() + if self._removed then + return + end + self._removed = true self._bar:remove() end -function mt:__close() - self:remove() +function mt:isRemoved() + return self._removed == true end ---@class workspace.loading.manager local m = {} +---@type table<workspace.loading, boolean> +m._loadings = setmetatable({}, { __mode = 'k' }) + ---@return workspace.loading function m.create(scp) local loading = setmetatable({ @@ -163,7 +172,20 @@ function m.create(scp) _cache = {}, }, mt) scp:set('cachedUris', loading._cache) + m._loadings[loading] = true return loading end +function m.count() + local num = 0 + for ld in pairs(m._loadings) do + if ld:isRemoved() then + m._loadings[ld] = nil + else + num = num + 1 + end + end + return num +end + return m |