summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-27 17:22:44 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-27 17:22:44 +0800
commit922ddb3ecabd4533b924792b0ffbfbf4d70de0a5 (patch)
tree18da0d83192b90db132799160f186584b23e73f4 /script/vm
parentde4baa7d9d874b81a4278a1e00a9f9548ba930ff (diff)
downloadlua-language-server-922ddb3ecabd4533b924792b0ffbfbf4d70de0a5.zip
lazy update globals
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/getGlobals.lua28
1 files changed, 21 insertions, 7 deletions
diff --git a/script/vm/getGlobals.lua b/script/vm/getGlobals.lua
index 87921284..e1fd0e7a 100644
--- a/script/vm/getGlobals.lua
+++ b/script/vm/getGlobals.lua
@@ -190,7 +190,25 @@ local function fastGetAnyGlobalSets()
return results
end
+local function checkNeedUpdate()
+ local getGlobalCache = ws.getCache 'getGlobals'
+ local getGlobalSetsCache = ws.getCache 'getGlobalSets'
+ local needUpdateGlobals = ws.getCache 'needUpdateGlobals'
+ for uri in pairs(needUpdateGlobals) do
+ needUpdateGlobals[uri] = nil
+ if files.exists(uri) then
+ for name in pairs(getGlobalsOfFile(uri)) do
+ getGlobalCache[name] = nil
+ end
+ for name in pairs(getGlobalSetsOfFile(uri)) do
+ getGlobalSetsCache[name] = nil
+ end
+ end
+ end
+end
+
function vm.getGlobals(key)
+ checkNeedUpdate()
local cache = ws.getCache('getGlobals')[key]
if cache ~= nil then
return cache
@@ -201,6 +219,7 @@ function vm.getGlobals(key)
end
function vm.getGlobalSets(key)
+ checkNeedUpdate()
local cache = ws.getCache('getGlobalSets')[key]
if cache ~= nil then
return cache
@@ -218,6 +237,7 @@ files.watch(function (ev, uri)
local globalSetsSubscribe = ws.getCache 'globalSetsSubscribe'
local getGlobalCache = ws.getCache 'getGlobals'
local getGlobalSetsCache = ws.getCache 'getGlobalSets'
+ local needUpdateGlobals = ws.getCache 'needUpdateGlobals'
uri = files.asKey(uri)
if globalSubscribe[uri] then
for _, name in ipairs(globalSubscribe[uri]) do
@@ -231,12 +251,6 @@ files.watch(function (ev, uri)
getGlobalSetsCache['*'] = nil
end
end
- -- TODO
- for name in pairs(getGlobalsOfFile(uri)) do
- getGlobalCache[name] = nil
- end
- for name in pairs(getGlobalSetsOfFile(uri)) do
- getGlobalSetsCache[name] = nil
- end
+ needUpdateGlobals[uri] = true
end
end)