summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2023-05-22 15:36:26 +0800
committer最萌小汐 <sumneko@hotmail.com>2023-05-22 15:36:26 +0800
commit86916250304abc76b4b54486851f33ac12e64caf (patch)
treeed5a84ac6d19f4413172c61f0901653c0cefa82d /script/vm
parent3bf4d7d022335657f237ac6d059ab1ce29af2232 (diff)
downloadlua-language-server-86916250304abc76b4b54486851f33ac12e64caf.zip
special searching for `__index`
#2106
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/compiler.lua38
1 files changed, 33 insertions, 5 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index d4309cc9..dc22f6b9 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -511,7 +511,7 @@ local function getReturnOfSetMetaTable(args)
node:merge(vm.compileNode(tbl))
end
if mt then
- vm.compileByParentNode(mt, '__index', function (src)
+ vm.compileByParentNodeAll(mt, '__index', function (src)
for n in vm.compileNode(src):eachObject() do
if n.type == 'global'
or n.type == 'local'
@@ -637,8 +637,9 @@ end
---@param source parser.object | vm.variable
---@param key string|vm.global|vm.ANY
----@param pushResult fun(source: parser.object)
-function vm.compileByParentNode(source, key, pushResult)
+---@return parser.object[] docedResults
+---@return parser.object[] commonResults
+function vm.getNodesOfParentNode(source, key)
local parentNode = vm.compileNode(source)
local docedResults = {}
local commonResults = {}
@@ -691,6 +692,16 @@ function vm.compileByParentNode(source, key, pushResult)
end)
end
+ return docedResults, commonResults
+end
+
+-- 遍历所有字段(按照优先级)
+---@param source parser.object | vm.variable
+---@param key string|vm.global|vm.ANY
+---@param pushResult fun(source: parser.object)
+function vm.compileByParentNode(source, key, pushResult)
+ local docedResults, commonResults = vm.getNodesOfParentNode(source, key)
+
if #docedResults > 0 then
for _, res in ipairs(docedResults) do
pushResult(res)
@@ -703,6 +714,21 @@ function vm.compileByParentNode(source, key, pushResult)
end
end
+-- 遍历所有字段(无视优先级)
+---@param source parser.object | vm.variable
+---@param key string|vm.global|vm.ANY
+---@param pushResult fun(source: parser.object)
+function vm.compileByParentNodeAll(source, key, pushResult)
+ local docedResults, commonResults = vm.getNodesOfParentNode(source, key)
+
+ for _, res in ipairs(docedResults) do
+ pushResult(res)
+ end
+ for _, res in ipairs(commonResults) do
+ pushResult(res)
+ end
+end
+
---@param list parser.object[]
---@param index integer
---@return vm.node
@@ -1341,8 +1367,10 @@ local compilerSwitch = util.switch()
end)
end
- if not hasMarkDoc and source.value then
- vm.setNode(source, vm.compileNode(source.value))
+ if source.value then
+ if not hasMarkDoc or source.value.type == 'table' then
+ vm.setNode(source, vm.compileNode(source.value))
+ end
end
end)