diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-07-01 15:15:49 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-07-01 15:15:49 +0800 |
commit | 8a50db2347486e2dd7380c8a1adf1964afe00feb (patch) | |
tree | 3ef4cd95ad985f1ec03e34d269b4efde1b33bc10 /script/workspace/workspace.lua | |
parent | b5c53c92555069c07b19618987c4d4d80226cf3e (diff) | |
download | lua-language-server-8a50db2347486e2dd7380c8a1adf1964afe00feb.zip |
improve progress
Diffstat (limited to 'script/workspace/workspace.lua')
-rw-r--r-- | script/workspace/workspace.lua | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua index 660ef879..e92870c1 100644 --- a/script/workspace/workspace.lua +++ b/script/workspace/workspace.lua @@ -221,18 +221,25 @@ local function loadFileFactory(root, progressData, isLibrary) progressData.max = progressData.max + 1 progressData:update() pub.task('loadFile', uri, function (text) - if text then - log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #text / 1000.0)) - if isLibrary then - log.info('++++As library of:', root) - files.setLibraryPath(uri, root) + local loader = function () + if text then + log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #text / 1024.0)) + if isLibrary then + log.info('++++As library of:', root) + files.setLibraryPath(uri, root) + end + files.setText(uri, text, false, true) + else + files.remove(uri) end - files.setText(uri, text, false) + progressData.read = progressData.read + 1 + progressData:update() + end + if progressData.loaders then + progressData.loaders[#progressData.loaders+1] = loader else - files.remove(uri) + loader() end - progressData.read = progressData.read + 1 - progressData:update() end) end if files.isDll(uri) then @@ -240,7 +247,7 @@ local function loadFileFactory(root, progressData, isLibrary) progressData.read = progressData.read + 1 progressData:update() if content then - log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1000.0)) + log.info(('Preload file at: %s , size = %.3f KB'):format(uri, #content / 1024.0)) if isLibrary then log.info('++++As library of:', root) end @@ -290,6 +297,7 @@ function m.awaitPreload() max = 0, read = 0, preload = 0, + loaders = {}, update = function (self) progressBar:setMessage(('%d/%d'):format(self.read, self.max)) progressBar:setPercentage(self.read / self.max * 100) @@ -311,6 +319,13 @@ function m.awaitPreload() library.matcher:scan(library.path, libraryLoader) end + await.call(function () + for _, loader in ipairs(progressData.loaders) do + loader() + await.delay() + end + end) + log.info(('Found %d files.'):format(progressData.max)) while true do log.info(('Loaded %d/%d files'):format(progressData.read, progressData.max)) |