diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-16 22:47:41 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-16 22:47:41 +0800 |
commit | e8fb2d2e0af8776662e010d334eb46ca1ccd7729 (patch) | |
tree | b475121f9e6754fcad97ca6edd001c5cf2466b66 /script | |
parent | 9d81f0cc079ff3ae32a48bc95aa9c18cfb0e3d64 (diff) | |
download | lua-language-server-e8fb2d2e0af8776662e010d334eb46ca1ccd7729.zip |
split progress
Diffstat (limited to 'script')
-rw-r--r-- | script/workspace/loading.lua | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua index 258c67d6..ad968cd4 100644 --- a/script/workspace/loading.lua +++ b/script/workspace/loading.lua @@ -14,6 +14,7 @@ local pub = require 'pub' ---@field _stash function[] ---@field _refs uri[] ---@field _cache table<uri, boolean> +---@field _sets function[] ---@field _removed boolean local mt = {} mt.__index = mt @@ -94,6 +95,9 @@ function mt:loadFile(uri, libraryUri) return end log.debug(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0)) + await.wait(function (waker) + self._sets[#self._sets+1] = waker + end) files.setText(uri, content, false) if not self._cache[uri] then files.addRef(uri) @@ -125,6 +129,9 @@ function mt:loadFile(uri, libraryUri) return end log.debug(('Preload dll at: %s , size = %.3f KB'):format(uri, #content / 1024.0)) + await.wait(function (waker) + self._sets[#self._sets+1] = waker + end) files.saveDll(uri, content) if not self._cache[uri] then files.addRef(uri) @@ -141,6 +148,8 @@ end ---@async function mt:loadAll() + local startClock = os.clock() + log.info('Load files from disk:', self.scp:getName()) while self.read < self.max do self:update() local loader = table.remove(self._stash) @@ -151,7 +160,17 @@ function mt:loadAll() await.sleep(0.1) end end - log.info('Loaded finish.') + local loadedClock = os.clock() + log.info(('Loaded files takes [%.3f] sec: %s'):format(loadedClock - startClock, self.scp:getName())) + self._bar:remove() + self._bar = progress.create(self.scp.uri, lang.script('WORKSPACE_LOADING', self.scp.uri), 0) + for i, set in ipairs(self._sets) do + set() + self.read = i + self:update() + end + log.info(('Compile files takes [%.3f] sec: %s'):format(os.clock() - loadedClock, self.scp:getName())) + log.info('Loaded finish:', self.scp:getName()) end function mt:remove() @@ -179,6 +198,7 @@ function m.create(scp) _bar = progress.create(scp.uri, lang.script('WORKSPACE_LOADING', scp.uri), 0.5), _stash = {}, _cache = {}, + _sets = {}, }, mt) m._loadings[loading] = true return loading |