summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-21 20:23:41 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-21 20:23:41 +0800
commitbb1244fa62c0158490d2e54da0a19f28f16fe994 (patch)
treebea39497ee52f7b4de442438bad50c90668a0647 /script/vm/compiler.lua
parentf76cd50992dab57a57c61e8e6f5f788745544da9 (diff)
downloadlua-language-server-bb1244fa62c0158490d2e54da0a19f28f16fe994.zip
resolve #871 infer called function by params num
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua39
1 files changed, 18 insertions, 21 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 99bd0691..515a8ebe 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -554,32 +554,29 @@ local function getReturn(func, index, args)
end
return vm.compileNode(ast)
end
- local node = vm.compileNode(func)
+ local funcs = vm.getMatchedFunctions(func, args)
---@type vm.node?
local result
- for cnode in node:eachObject() do
- if cnode.type == 'function'
- or cnode.type == 'doc.type.function' then
- local returnObject = vm.getReturnOfFunction(cnode, index)
- if returnObject then
- local returnNode = vm.compileNode(returnObject)
+ for _, mfunc in ipairs(funcs) do
+ local returnObject = vm.getReturnOfFunction(mfunc, index)
+ if returnObject then
+ local returnNode = vm.compileNode(returnObject)
+ for rnode in returnNode:eachObject() do
+ if rnode.type == 'generic' then
+ returnNode = rnode:resolve(guide.getUri(func), args)
+ break
+ end
+ end
+ if returnNode then
for rnode in returnNode:eachObject() do
- if rnode.type == 'generic' then
- returnNode = rnode:resolve(guide.getUri(func), args)
- break
+ -- TODO: narrow type
+ if rnode.type ~= 'doc.generic.name' then
+ result = result or vm.createNode()
+ result:merge(rnode)
end
end
- if returnNode then
- for rnode in returnNode:eachObject() do
- -- TODO: narrow type
- if rnode.type ~= 'doc.generic.name' then
- result = result or vm.createNode()
- result:merge(rnode)
- end
- end
- if result and returnNode:isOptional() then
- result:addOptional()
- end
+ if result and returnNode:isOptional() then
+ result:addOptional()
end
end
end