diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-26 21:08:01 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-26 21:08:01 +0800 |
commit | c513bcd6149bb3467b17b20a106087b8f418a0b1 (patch) | |
tree | c4eda47d23079518567ff4da35fceef6856536cb | |
parent | e23fa5859ee8f9424aaeed7dbc6d5ce90bc7dd44 (diff) | |
download | lua-language-server-c513bcd6149bb3467b17b20a106087b8f418a0b1.zip |
improve loading process
-rw-r--r-- | script/workspace/loading.lua | 19 | ||||
-rw-r--r-- | 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) |