summaryrefslogtreecommitdiff
path: root/script/vm/sign.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-11-01 13:31:30 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-11-01 13:31:30 +0800
commite63ccd8fec249fdcade372f1c664733dacdc131e (patch)
tree45e6ed4dac31f375db45c50e55a12180a7294b9e /script/vm/sign.lua
parent4d65d77f5214bf5dd935956c861580ff2b46bfe4 (diff)
downloadlua-language-server-e63ccd8fec249fdcade372f1c664733dacdc131e.zip
cleanup
Diffstat (limited to 'script/vm/sign.lua')
-rw-r--r--script/vm/sign.lua69
1 files changed, 69 insertions, 0 deletions
diff --git a/script/vm/sign.lua b/script/vm/sign.lua
index 21044a28..3791ca4f 100644
--- a/script/vm/sign.lua
+++ b/script/vm/sign.lua
@@ -260,3 +260,72 @@ function vm.createSign()
}, mt)
return genericMgr
end
+
+---@class parser.object
+---@field package _sign vm.sign|false|nil
+
+---@param source parser.object
+---@param sign vm.sign
+function vm.setSign(source, sign)
+ source._sign = sign
+end
+
+---@param source parser.object
+---@return vm.sign?
+function vm.getSign(source)
+ if source._sign ~= nil then
+ return source._sign or nil
+ end
+ source._sign = false
+ if source.type == 'function' then
+ if not source.bindDocs then
+ return nil
+ end
+ for _, doc in ipairs(source.bindDocs) do
+ if doc.type == 'doc.generic' then
+ if not source._sign then
+ source._sign = vm.createSign()
+ break
+ end
+ end
+ end
+ if not source._sign then
+ return nil
+ end
+ if source.args then
+ for _, arg in ipairs(source.args) do
+ local argNode = vm.compileNode(arg)
+ if arg.optional then
+ argNode:addOptional()
+ end
+ source._sign:addSign(argNode)
+ end
+ end
+ end
+ if source.type == 'doc.type.function'
+ or source.type == 'doc.type.table'
+ or source.type == 'doc.type.array' then
+ local hasGeneric
+ guide.eachSourceType(source, 'doc.generic.name', function ()
+ hasGeneric = true
+ end)
+ if not hasGeneric then
+ return nil
+ end
+ source._sign = vm.createSign()
+ if source.type == 'doc.type.function' then
+ for _, arg in ipairs(source.args) do
+ if arg.extends then
+ local argNode = vm.compileNode(arg.extends)
+ if arg.optional then
+ argNode:addOptional()
+ end
+ source._sign:addSign(argNode)
+ else
+ source._sign:addSign(vm.createNode())
+ end
+ end
+ end
+ end
+ return source._sign or nil
+end