summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-01-04 20:56:29 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-01-04 20:56:29 +0800
commit1befa0b9aa893ad11acb858df5e3c636b05435c0 (patch)
tree1bc30f319b73cc28cf30f9e3d1275cc3aafccc96
parent702b0e7abe33f099e26ce48fdd4d82d6c8d7af0e (diff)
downloadlua-language-server-1befa0b9aa893ad11acb858df5e3c636b05435c0.zip
fix removing dead nodes
-rw-r--r--script/vm/compiler.lua36
-rw-r--r--script/vm/node.lua4
-rw-r--r--script/vm/variable-id.lua1
3 files changed, 21 insertions, 20 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 43c372a0..325c75e2 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1235,27 +1235,29 @@ local compilerSwitch = util.switch()
end
---@type vm.node, boolean
- local cacheNode, needCompile
+ local variableNode, needCompile
do
local localInfo = vm.getVariableInfo(source)
if localInfo then
- cacheNode = localInfo.node
- if not cacheNode then
+ local lastCacheNode = vm.getNode(localInfo)
+ if lastCacheNode then
+ variableNode = lastCacheNode
+ else
needCompile = true
- cacheNode = vm.createNode()
- localInfo.node = cacheNode
+ variableNode = vm.createNode()
+ vm.setNode(localInfo, variableNode, true)
end
else
local parentNode = vm.compileNode(source.node)
if not parentNode.fields then
parentNode.fields = {}
end
- cacheNode = parentNode.fields[key]
- if not cacheNode then
+ variableNode = parentNode.fields[key]
+ if not variableNode then
needCompile = true
- cacheNode = vm.createNode()
- parentNode.fields[key] = cacheNode
+ variableNode = vm.createNode()
+ parentNode.fields[key] = variableNode
end
end
end
@@ -1266,15 +1268,15 @@ local compilerSwitch = util.switch()
local uri = guide.getUri(source)
local value = vm.getTableValue(uri, vm.compileNode(source.node), key)
if value then
- cacheNode:merge(value)
+ variableNode:merge(value)
end
for k in key:eachObject() do
if k.type == 'global' and k.cate == 'type' then
---@cast k vm.global
vm.compileByParentNode(source.node, k, function (src)
- cacheNode:merge(vm.compileNode(src))
+ variableNode:merge(vm.compileNode(src))
if src.value then
- cacheNode:merge(vm.compileNode(src.value))
+ variableNode:merge(vm.compileNode(src.value))
end
end)
end
@@ -1284,21 +1286,21 @@ local compilerSwitch = util.switch()
vm.compileByParentNode(source.node, key, function (src)
if src.value then
if bindDocs(src) then
- cacheNode:merge(vm.compileNode(src))
+ variableNode:merge(vm.compileNode(src))
elseif src.value.type ~= 'nil' then
- cacheNode:merge(vm.compileNode(src.value))
+ variableNode:merge(vm.compileNode(src.value))
local node = vm.getNode(src)
if node then
- cacheNode:merge(node)
+ variableNode:merge(node)
end
end
else
- cacheNode:merge(vm.compileNode(src))
+ variableNode:merge(vm.compileNode(src))
end
end)
end
end
- vm.setNode(source, cacheNode)
+ vm.setNode(source, variableNode)
end)
: case 'setglobal'
: call(function (source)
diff --git a/script/vm/node.lua b/script/vm/node.lua
index ec1b9ef2..d45ed6a7 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -384,7 +384,7 @@ function mt:copy()
return vm.createNode(self)
end
----@param source vm.object
+---@param source vm.object | vm.variable
---@param node vm.node | vm.node.object
---@param cover? boolean
---@return vm.node
@@ -415,7 +415,7 @@ function vm.setNode(source, node, cover)
return me
end
----@param source vm.object
+---@param source vm.object | vm.variable
---@return vm.node?
function vm.getNode(source)
return vm.nodeCache[source]
diff --git a/script/vm/variable-id.lua b/script/vm/variable-id.lua
index 8e8d4ed0..e5257776 100644
--- a/script/vm/variable-id.lua
+++ b/script/vm/variable-id.lua
@@ -6,7 +6,6 @@ local vm = require 'vm.vm'
---@class vm.variable
---@field sets parser.object[]
---@field gets parser.object[]
----@field node? vm.node
---@class parser.object
---@field package _variableID string|false