summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-07-05 14:50:16 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-07-05 14:50:16 +0800
commit60189b2603798bba46e0c0aefdbad575efebfcee (patch)
tree1a8894c7d32177428dcb268ab4bf3150d9e8eee6 /script
parentd086077b0ecd351319504f3e0fcef9912c4fedb4 (diff)
downloadlua-language-server-60189b2603798bba46e0c0aefdbad575efebfcee.zip
fix #1267
Diffstat (limited to 'script')
-rw-r--r--script/vm/compiler.lua3
-rw-r--r--script/vm/node.lua27
2 files changed, 29 insertions, 1 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index e361d706..1936fc75 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1309,7 +1309,8 @@ local compilerSwitch = util.switch()
end
if src.value then
if src.value.type == 'table' then
- vm.setNode(src, vm.createNode(src.value), true)
+ vm.setNode(src, vm.createNode(src.value))
+ vm.setNode(src, node:copy():asTable())
else
vm.setNode(src, vm.compileNode(src.value), true)
end
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 45e5e6c4..f0d0b0ba 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -227,6 +227,7 @@ function mt:remove(name)
or (c.type == 'doc.type.boolean' and name == 'false' and c[1] == false)
or (c.type == 'doc.type.table' and name == 'table')
or (c.type == 'doc.type.array' and name == 'table')
+ or (c.type == 'doc.type.sign' and name == 'table')
or (c.type == 'doc.type.function' and name == 'function') then
table.remove(self, index)
self[c] = nil
@@ -247,6 +248,7 @@ function mt:narrow(name)
or (c.type == 'doc.type.boolean' and name == 'boolean')
or (c.type == 'doc.type.table' and name == 'table')
or (c.type == 'doc.type.array' and name == 'table')
+ or (c.type == 'doc.type.sign' and name == 'table')
or (c.type == 'doc.type.function' and name == 'function') then
goto CONTINUE
end
@@ -328,6 +330,31 @@ function mt:hasName(name)
return false
end
+---@return vm.node
+function mt:asTable()
+ self.optional = nil
+ for index = #self, 1, -1 do
+ local c = self[index]
+ if c.type == 'table'
+ or c.type == 'doc.type.table'
+ or c.type == 'doc.type.array'
+ or c.type == 'doc.type.sign' then
+ goto CONTINUE
+ end
+ if c.type == 'global' and c.cate == 'type' then
+ ---@cast c vm.global
+ if c.name == 'table'
+ or not guide.isBasicType(c.name) then
+ goto CONTINUE
+ end
+ end
+ table.remove(self, index)
+ self[c] = nil
+ ::CONTINUE::
+ end
+ return self
+end
+
---@return fun():vm.node.object
function mt:eachObject()
local i = 0