Skip to content

Commit c513bcd

Browse files
committed
improve loading process
1 parent e23fa58 commit c513bcd

File tree

2 files changed

+20
-24
lines changed

2 files changed

+20
-24
lines changed

script/workspace/loading.lua

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,23 +134,18 @@ function mt:loadFile(uri, libraryUri)
134134
await.delay()
135135
end
136136

137-
function mt:loadStashed(max)
138-
for _ = 1, max do
139-
local loader = table.remove(self._stash)
140-
if not loader then
141-
return
142-
end
143-
await.call(loader)
144-
end
145-
end
146-
147137
---@async
148138
function mt:loadAll()
149139
while self.read < self.max do
150140
log.info(('Loaded %d/%d files'):format(self.read, self.max))
151-
self:loadStashed(100)
152141
self:update()
153-
await.sleep(0.1)
142+
local loader = table.remove(self._stash)
143+
if loader then
144+
await.call(loader)
145+
await.delay()
146+
else
147+
await.sleep(0.1)
148+
end
154149
end
155150
log.info('Loaded finish.')
156151
end

script/workspace/workspace.lua

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,10 +491,11 @@ end)
491491

492492
fw.event(function (changes) ---@async
493493
for _, change in ipairs(changes) do
494+
local path = change.path
495+
local uri = furi.encode(path)
496+
494497
---@async
495498
await.call(function ()
496-
local path = change.path
497-
local uri = furi.encode(path)
498499
if change.type == 'create' then
499500
log.debug('FileChangeType.Created', uri)
500501
m.awaitLoadFile(uri)
@@ -514,19 +515,19 @@ fw.event(function (changes) ---@async
514515
if not files.isOpen(uri) then
515516
files.setText(uri, pub.awaitTask('loadFile', furi.decode(uri)), false)
516517
end
517-
else
518-
local filename = fs.path(path):filename():string()
519-
-- 排除类文件发生更改需要重新扫描
520-
if filename == '.gitignore'
521-
or filename == '.gitmodules' then
522-
local scp = scope.getScope(uri)
523-
if scp.type ~= 'fallback' then
524-
m.reload(scp)
525-
end
526-
end
527518
end
528519
end
529520
end)
521+
522+
local filename = fs.path(path):filename():string()
523+
-- 排除类文件发生更改需要重新扫描
524+
if filename == '.gitignore'
525+
or filename == '.gitmodules' then
526+
local scp = scope.getScope(uri)
527+
if scp.type ~= 'fallback' then
528+
m.reload(scp)
529+
end
530+
end
530531
end
531532
end)
532533

0 commit comments

Comments
 (0)