summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-07-14 17:13:28 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-07-14 17:13:28 +0800
commitf0fd80ee70928ba27775c0fe40de30c7b936bdb0 (patch)
tree34d5ddd8c3edbdc2725a99b37543bcc268e4999c
parent826175b57368d6daace55cec051aba2aba8ab019 (diff)
downloadlua-language-server-f0fd80ee70928ba27775c0fe40de30c7b936bdb0.zip
fix loading workspace may hang
-rw-r--r--changelog.md1
-rw-r--r--script/workspace/workspace.lua23
2 files changed, 19 insertions, 5 deletions
diff --git a/changelog.md b/changelog.md
index 7eafe189..4ffb00c5 100644
--- a/changelog.md
+++ b/changelog.md
@@ -3,6 +3,7 @@
## 2.3.0
* `NEW` `VSCode`: click the status bar icon to operate:
* run workspace diagnostics
+* `FIX` loading workspace may hang
* `FIX` `debug.getuservalue` and `debug.setuservalue` should not exist in `Lua 5.1`
* `FIX` infer of `---@type class[][]`
* `FIX` infer of `---@type {}[]`
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index fcfde027..e69c6d76 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -320,15 +320,28 @@ function m.awaitPreload()
library.matcher:scan(library.path, libraryLoader)
end
- await.call(function ()
- for _, loader in ipairs(progressData.loaders) do
- loader()
- await.delay()
+ local isLoadingFiles = false
+ local function loadSomeFiles()
+ if isLoadingFiles then
+ return
end
- end)
+ await.call(function ()
+ isLoadingFiles = true
+ while true do
+ local loader = table.remove(progressData.loaders)
+ if not loader then
+ break
+ end
+ loader()
+ await.delay()
+ end
+ isLoadingFiles = false
+ end)
+ end
log.info(('Found %d files.'):format(progressData.max))
while true do
+ loadSomeFiles()
log.info(('Loaded %d/%d files'):format(progressData.read, progressData.max))
progressData:update()
if progressData.read >= progressData.max then