summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-01-21 17:34:46 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-01-21 17:34:46 +0800
commit4d538055a120ff39fe40e9c73bb40df5645c50e4 (patch)
tree3ac853dbc3924f0096381b9495a2695a763ac4d7
parent3778e5eeb3ffe35e5a5f70700635a90970a2ee40 (diff)
downloadlua-language-server-4d538055a120ff39fe40e9c73bb40df5645c50e4.zip
update
-rw-r--r--script/files.lua16
-rw-r--r--script/provider/diagnostic.lua8
-rw-r--r--script/workspace/loading.lua66
3 files changed, 59 insertions, 31 deletions
diff --git a/script/files.lua b/script/files.lua
index 009beba4..0b6c1e09 100644
--- a/script/files.lua
+++ b/script/files.lua
@@ -417,20 +417,20 @@ function m.remove(uri)
end
--- 获取一个包含所有文件uri的数组
+---@param scp? scope
---@return uri[]
-function m.getAllUris()
- local files = m._pairsCache
+function m.getAllUris(scp)
+ local files = {}
local i = 0
- if not files then
- files = {}
- m._pairsCache = files
- for uri in pairs(m.fileMap) do
+ for uri in pairs(m.fileMap) do
+ if not scp
+ or scp:isChildUri(uri)
+ or scp:isLinkedUri(uri) then
i = i + 1
files[i] = uri
end
- table.sort(files)
end
- return m._pairsCache
+ return files
end
--- 遍历文件
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index 3152c332..0a3c4384 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -10,6 +10,7 @@ local ws = require 'workspace'
local progress = require "progress"
local client = require 'client'
local converter = require 'proto.converter'
+local loading = require 'workspace.loading'
---@class diagnosticProvider
local m = {}
@@ -364,8 +365,13 @@ function m.diagnosticsScope(uri, force)
askForDisable(uri)
end)
end)
- local uris = files.getAllUris()
+ local scp = ws.getScope(uri)
+ local uris = files.getAllUris(scp)
+ log.info(('diagnostics scope [%s], files count:[%d]'):format(scp, #uris))
for i, uri in ipairs(uris) do
+ while loading.count() > 0 do
+ await.sleep(1.0)
+ end
bar:setMessage(('%d/%d'):format(i, #uris))
bar:setPercentage(i / #uris * 100)
xpcall(m.doDiagnostic, log.error, uri, true)
diff --git a/script/workspace/loading.lua b/script/workspace/loading.lua
index 19fe0728..8091cadf 100644
--- a/script/workspace/loading.lua
+++ b/script/workspace/loading.lua
@@ -13,6 +13,7 @@ local furi = require 'file-uri'
---@field _stash function[]
---@field _refs uri[]
---@field _cache table<uri, boolean>
+---@field _removed boolean
local mt = {}
mt.__index = mt
@@ -21,6 +22,10 @@ mt.read = 0
mt.max = 0
mt.preload = 0
+function mt:__close()
+ self:remove()
+end
+
function mt:update()
self._bar:setMessage(('%d/%d'):format(self.read, self.max))
self._bar:setPercentage(self.read / self.max * 100.0)
@@ -114,46 +119,50 @@ function mt:loadFile(uri, libraryUri)
await.delay()
end
-function mt:loadStashed()
- self:update()
- if self._loadLock then
- return
- end
- self._loadLock = true
- ---@async
- await.call(function ()
- while true do
- local loader = table.remove(self._stash)
- if not loader then
- break
- end
- loader()
- await.delay()
+---@async
+function mt:loadStashed(max)
+ for _ = 1, max do
+ local loader = table.remove(self._stash)
+ if not loader then
+ return false
end
- self._loadLock = false
- end)
+ loader()
+ await.delay()
+ end
+ return true
end
---@async
function mt:loadAll()
- while self.read < self.max do
+ while true do
log.info(('Loaded %d/%d files'):format(self.read, self.max))
- self:loadStashed()
- await.sleep(0.1)
+ local suc = self:loadStashed(10)
+ self:update()
+ if not suc then
+ break
+ end
end
+ log.info('Loaded finish.')
end
function mt:remove()
+ if self._removed then
+ return
+ end
+ self._removed = true
self._bar:remove()
end
-function mt:__close()
- self:remove()
+function mt:isRemoved()
+ return self._removed == true
end
---@class workspace.loading.manager
local m = {}
+---@type table<workspace.loading, boolean>
+m._loadings = setmetatable({}, { __mode = 'k' })
+
---@return workspace.loading
function m.create(scp)
local loading = setmetatable({
@@ -163,7 +172,20 @@ function m.create(scp)
_cache = {},
}, mt)
scp:set('cachedUris', loading._cache)
+ m._loadings[loading] = true
return loading
end
+function m.count()
+ local num = 0
+ for ld in pairs(m._loadings) do
+ if ld:isRemoved() then
+ m._loadings[ld] = nil
+ else
+ num = num + 1
+ end
+ end
+ return num
+end
+
return m