summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-08 16:27:36 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-08 16:27:36 +0800
commitf33b06fd928fd3541eea99b11ee6caf9b249a49b (patch)
tree3b46df792bd8324f07ee03c003b50ffa9f413af8
parent78b3a317d66d3066ccda8570737e2ecbe76c6568 (diff)
downloadlua-language-server-f33b06fd928fd3541eea99b11ee6caf9b249a49b.zip
try flush cache
-rw-r--r--script/vm/compiler.lua41
-rw-r--r--test/diagnostics/common.lua14
2 files changed, 36 insertions, 19 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index eeea3c87..08fc2296 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -659,6 +659,7 @@ local compilerSwitch = util.switch()
if not source.value
and source.ref
and not hasMarkDoc then
+ m.pauseCache()
for _, ref in ipairs(source.ref) do
if ref.type == 'setlocal' then
if ref.value and ref.value.type == 'table' then
@@ -668,6 +669,7 @@ local compilerSwitch = util.switch()
end
end
end
+ m.resumeCache()
end
-- function x.y(self, ...) --> function x:y(...)
if source[1] == 'self'
@@ -707,20 +709,6 @@ local compilerSwitch = util.switch()
if source.parent.type == 'loop' then
nodeMgr.setNode(source, globalMgr.getGlobal('type', 'integer'))
end
-
- -- avoid self reference
- -- `local x; x = x`
- -- the third `x` is unknown here
- -- x[1] -> value of x[2] -> x[3] -> x[1](locked!)
- if source.ref then
- local myNode = nodeMgr.getNode(source)
- for _, ref in ipairs(source.ref) do
- if ref.type == 'setlocal'
- or ref.type == 'getlocal' then
- nodeMgr.setNode(ref, myNode, true)
- end
- end
- end
end)
: case 'setlocal'
: case 'getlocal'
@@ -1413,6 +1401,24 @@ local function compileByGlobal(source)
end
end
+local pauseCacheCount = 0
+local originCacheKeys = {}
+local originCacheValues = {}
+function m.pauseCache()
+ pauseCacheCount = pauseCacheCount + 1
+end
+
+function m.resumeCache()
+ pauseCacheCount = pauseCacheCount - 1
+ if pauseCacheCount == 0 then
+ for source in pairs(originCacheKeys) do
+ nodeMgr.nodeCache[source] = originCacheValues[source]
+ originCacheKeys[source] = nil
+ originCacheValues[source] = nil
+ end
+ end
+end
+
---@param source parser.object
---@return vm.node
function m.compileNode(source)
@@ -1422,6 +1428,13 @@ function m.compileNode(source)
if nodeMgr.nodeCache[source] ~= nil then
return nodeMgr.nodeCache[source]
end
+
+ local pauseCache = pauseCacheCount > 0
+ if pauseCache and not originCacheKeys[source] then
+ originCacheKeys[source] = true
+ originCacheValues[source] = nodeMgr.nodeCache[source]
+ end
+
nodeMgr.nodeCache[source] = false
compileByGlobal(source)
compileByNode(source)
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index 722bdea7..6aa1dd6a 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -1378,8 +1378,12 @@ TEST [[
---@class A 1
]]
---TEST [[
---local value
---value = '1'
---value = value:gsub()
---]]
+TEST [[
+return ('1'):gsub()
+]]
+
+TEST [[
+local value
+value = '1'
+value = value:gsub()
+]]