From c513bcd6149bb3467b17b20a106087b8f418a0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 26 Jan 2022 21:08:01 +0800 Subject: improve loading process --- script/workspace/loading.lua | 19 +++++++------------ script/workspace/workspace.lua | 25 +++++++++++++------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua index 12683a23..aedd74a0 100644 --- a/script/workspace/loading.lua +++ b/script/workspace/loading.lua @@ -134,23 +134,18 @@ function mt:loadFile(uri, libraryUri) await.delay() end -function mt:loadStashed(max) - for _ = 1, max do - local loader = table.remove(self._stash) - if not loader then - return - end - await.call(loader) - end -end - ---@async function mt:loadAll() while self.read < self.max do log.info(('Loaded %d/%d files'):format(self.read, self.max)) - self:loadStashed(100) self:update() - await.sleep(0.1) + local loader = table.remove(self._stash) + if loader then + await.call(loader) + await.delay() + else + await.sleep(0.1) + end end log.info('Loaded finish.') end diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index ad28d76b..cb1ad58c 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -491,10 +491,11 @@ end) fw.event(function (changes) ---@async for _, change in ipairs(changes) do + local path = change.path + local uri = furi.encode(path) + ---@async await.call(function () - local path = change.path - local uri = furi.encode(path) if change.type == 'create' then log.debug('FileChangeType.Created', uri) m.awaitLoadFile(uri) @@ -514,19 +515,19 @@ fw.event(function (changes) ---@async if not files.isOpen(uri) then files.setText(uri, pub.awaitTask('loadFile', furi.decode(uri)), false) end - else - local filename = fs.path(path):filename():string() - -- 排除类文件发生更改需要重新扫描 - if filename == '.gitignore' - or filename == '.gitmodules' then - local scp = scope.getScope(uri) - if scp.type ~= 'fallback' then - m.reload(scp) - end - end end end end) + + local filename = fs.path(path):filename():string() + -- 排除类文件发生更改需要重新扫描 + if filename == '.gitignore' + or filename == '.gitmodules' then + local scp = scope.getScope(uri) + if scp.type ~= 'fallback' then + m.reload(scp) + end + end end end) -- cgit v1.2.3