summaryrefslogtreecommitdiff
path: root/script/vm
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-22 03:54:03 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-22 03:54:03 +0800
commitb26b7f7029d895c672a0a4d057d00b36355acaa7 (patch)
treec98b1398b9fc1f1caf787c5e28bf17c8a312d7db /script/vm
parent4c6375fea56e5362afc8eef1a4d32ebbe64c7391 (diff)
downloadlua-language-server-b26b7f7029d895c672a0a4d057d00b36355acaa7.zip
resolve `T[]` by `doc.type.table` or `doc.field`
Diffstat (limited to 'script/vm')
-rw-r--r--script/vm/compiler.lua28
-rw-r--r--script/vm/sign.lua13
2 files changed, 32 insertions, 9 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 883d89b9..4395eea4 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -184,7 +184,7 @@ local searchFieldSwitch = util.switch()
end)
-function vm.getClassFields(suri, node, key, ref, pushResult)
+function vm.getClassFields(suri, object, key, ref, pushResult)
local mark = {}
local function searchClass(class, searchedFields)
@@ -199,13 +199,23 @@ function vm.getClassFields(suri, node, key, ref, pushResult)
-- check ---@field
local hasFounded = {}
for _, field in ipairs(set.fields) do
- local fieldKey = guide.getKeyName(field)
- if fieldKey then
- if key == nil
- or fieldKey == key then
- if not searchedFields[fieldKey] then
+ if type(key) == 'table' then
+ local fieldNode = vm.compileNode(field.field)
+ if vm.isSubType(suri, key.name, fieldNode) then
+ if not searchedFields[key] then
pushResult(field)
- hasFounded[fieldKey] = true
+ hasFounded[key] = true
+ end
+ end
+ else
+ local fieldKey = guide.getKeyName(field)
+ if fieldKey then
+ if key == nil
+ or fieldKey == key then
+ if not searchedFields[fieldKey] then
+ pushResult(field)
+ hasFounded[fieldKey] = true
+ end
end
end
end
@@ -273,8 +283,8 @@ function vm.getClassFields(suri, node, key, ref, pushResult)
end
end
- searchClass(node)
- searchGlobal(node)
+ searchClass(object)
+ searchGlobal(object)
end
---@class parser.object
diff --git a/script/vm/sign.lua b/script/vm/sign.lua
index e997624a..78d61022 100644
--- a/script/vm/sign.lua
+++ b/script/vm/sign.lua
@@ -49,6 +49,19 @@ function mt:resolve(uri, args, removeGeneric)
-- number[] -> T[]
resolve(object.node, vm.compileNode(n.node))
end
+ if n.type == 'doc.type.table' then
+ -- { [integer]: number } -> T[]
+ local tvalueNode = vm.getTableValue(uri, node, 'integer')
+ if tvalueNode then
+ resolve(object.node, tvalueNode)
+ end
+ end
+ if n.type == 'global' and n.cate == 'type' then
+ -- ---@field [integer]: number -> T[]
+ vm.getClassFields(uri, n, globalMgr.getGlobal('type', 'integer'), false, function (field)
+ resolve(object.node, vm.compileNode(field.extends))
+ end)
+ end
end
end
if object.type == 'doc.type.table' then