summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-17 16:48:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-17 16:48:43 +0800
commitcf20156aa05c074d3f8ea2bf12277b4b06dfc8c4 (patch)
treeaf108da2ace7c12f3f21f289f89f3d454c0e1541
parent1bcadf492c4ccc19d137ffac80b0e9ca181a9ad7 (diff)
downloadlua-language-server-cf20156aa05c074d3f8ea2bf12277b4b06dfc8c4.zip
cleanup
-rw-r--r--script/vm/compiler.lua2
-rw-r--r--script/vm/type.lua92
2 files changed, 44 insertions, 50 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 65df3a1d..c7d57dcb 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -230,7 +230,7 @@ function vm.getClassFields(suri, object, key, ref, pushResult)
or keyType == 'string' then
typeName = keyType
end
- if typeName then
+ if typeName and field.field.type ~= 'doc.field.name' then
-- ---@field [integer] boolean -> class[1]
local fieldNode = vm.compileNode(field.field)
if vm.isSubType(suri, typeName, fieldNode) then
diff --git a/script/vm/type.lua b/script/vm/type.lua
index e2f723bc..50c9efa7 100644
--- a/script/vm/type.lua
+++ b/script/vm/type.lua
@@ -31,12 +31,42 @@ local function getNodeName(object)
return nil
end
----@param child vm.object
----@param parent vm.object
+---@param uri uri
+---@param child vm.node|string|vm.object
+---@param parent vm.node|string|vm.object
---@param mark? table
---@return boolean
-function vm.isSubNode(child, parent, mark)
+function vm.isSubType(uri, child, parent, mark)
mark = mark or {}
+
+ if type(child) == 'string' then
+ child = vm.getGlobal('type', child)
+ if not child then
+ return false
+ end
+ elseif child.type == 'vm.node' then
+ for n in child:eachObject() do
+ if getNodeName(n) and not vm.isSubType(uri, n, parent, mark) then
+ return false
+ end
+ end
+ return true
+ end
+
+ if type(parent) == 'string' then
+ parent = vm.getGlobal('type', parent)
+ if not parent then
+ return false
+ end
+ elseif parent.type == 'vm.node' then
+ for n in parent:eachObject() do
+ if getNodeName(n) and not vm.isSubType(uri, child, n, mark) then
+ return false
+ end
+ end
+ return true
+ end
+
local childName = getNodeName(child)
local parentName = getNodeName(parent)
if childName == 'any'
@@ -48,52 +78,16 @@ function vm.isSubNode(child, parent, mark)
return true
end
- return false
-end
-
----@param uri uri
----@param child vm.node|string
----@param parent vm.node|string
----@param mark? table
----@return boolean
-function vm.isSubType(uri, child, parent, mark)
- if type(parent) == 'string' then
- parent = vm.createNode(vm.getGlobal('type', parent))
- end
- if type(child) == 'string' then
- child = vm.createNode(vm.getGlobal('type', child))
- end
-
- if not child or not parent then
- return false
- end
-
- mark = mark or {}
- for childNode in child:eachObject() do
- if not mark[childNode] then
- mark[childNode] = true
- for parentNode in parent:eachObject() do
- if vm.isSubNode(childNode, parentNode, mark) then
- return true
- end
- end
-
- if childNode.type == 'global' and childNode.cate == 'type' then
- for _, set in ipairs(childNode:getSets(uri)) do
- if set.type == 'doc.class' and set.extends then
- for _, ext in ipairs(set.extends) do
- if ext.type == 'doc.extends.name'
- and vm.isSubType(uri, ext[1], parent, mark) then
- return true
- end
- end
- end
- if set.type == 'doc.alias' and set.extends then
- for _, ext in ipairs(set.extends.types) do
- if ext.type == 'doc.type.name'
- and vm.isSubType(uri, ext[1], parent, mark) then
- return true
- end
+ -- check class parent
+ if not mark[child] then
+ mark[child] = true
+ if child.type == 'global' and child.cate == 'type' then
+ for _, set in ipairs(child:getSets(uri)) do
+ if set.type == 'doc.class' and set.extends then
+ for _, ext in ipairs(set.extends) do
+ if ext.type == 'doc.extends.name'
+ and vm.isSubType(uri, ext[1], parent, mark) then
+ return true
end
end
end