summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-04-21 02:04:22 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-04-21 02:04:22 +0800
commitc2cf059ec21bb1076913bb99132d1f1cabf00d67 (patch)
treec082e15cda982afdb683196bdc9d20c8437e7e4f /script
parentfa3736b7532a0d64e20e77a667e2e83528e0a01d (diff)
downloadlua-language-server-c2cf059ec21bb1076913bb99132d1f1cabf00d67.zip
supports infer of callback parameter
Diffstat (limited to 'script')
-rw-r--r--script/vm/compiler.lua33
-rw-r--r--script/vm/generic.lua2
-rw-r--r--script/vm/sign.lua3
3 files changed, 31 insertions, 7 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index ca01a138..eea6e093 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -289,6 +289,9 @@ local function getObjectSign(source)
end
source._sign = false
if source.type == 'function' then
+ if not source.bindDocs then
+ return false
+ end
for _, doc in ipairs(source.bindDocs) do
if doc.type == 'doc.generic' then
if not source._sign then
@@ -323,11 +326,15 @@ local function getObjectSign(source)
source._sign = signMgr()
if source.type == 'doc.type.function' then
for _, arg in ipairs(source.args) do
- local argNode = vm.compileNode(arg.extends)
- if arg.optional then
- argNode:addOptional()
+ 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
- source._sign:addSign(argNode)
end
end
end
@@ -673,10 +680,21 @@ local function compileCallArgNode(arg, call, callNode, fixIndex, myIndex)
for n in callNode:eachObject() do
if n.type == 'function' then
+ local sign = getObjectSign(n)
local farg = getFuncArg(n, myIndex)
if farg then
for fn in vm.compileNode(farg):eachObject() do
if isValidCallArgNode(arg, fn) then
+ if fn.type == 'doc.type.function' then
+ if sign then
+ local generic = genericMgr(fn, sign)
+ local args = {}
+ for i = fixIndex + 1, myIndex - 1 do
+ args[#args+1] = call.args[i]
+ end
+ fn = generic:resolve(guide.getUri(call), args)
+ end
+ end
vm.setNode(arg, fn)
end
end
@@ -797,7 +815,12 @@ local function compileLocalBase(source)
if n.type == 'doc.type.function' then
for index, arg in ipairs(n.args) do
if func.args[index] == source then
- vm.setNode(source, vm.compileNode(arg))
+ local argNode = vm.compileNode(arg)
+ for an in argNode:eachObject() do
+ if an.type ~= 'doc.generic.name' then
+ vm.setNode(source, an)
+ end
+ end
hasDocArg = true
end
end
diff --git a/script/vm/generic.lua b/script/vm/generic.lua
index b3981ff8..b58c7bce 100644
--- a/script/vm/generic.lua
+++ b/script/vm/generic.lua
@@ -114,7 +114,7 @@ end
---@param uri uri
---@param args parser.object
----@return parser.object
+---@return vm.node
function mt:resolve(uri, args)
local resolved = self.sign:resolve(uri, args)
local protoNode = vm.compileNode(self.proto)
diff --git a/script/vm/sign.lua b/script/vm/sign.lua
index 257166ce..e997624a 100644
--- a/script/vm/sign.lua
+++ b/script/vm/sign.lua
@@ -16,8 +16,9 @@ end
---@param uri uri
---@param args parser.object
+---@param removeGeneric true?
---@return table<string, vm.node>
-function mt:resolve(uri, args)
+function mt:resolve(uri, args, removeGeneric)
if not args then
return nil
end