summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-14 19:14:34 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-14 19:14:34 +0800
commitdd1c80a8ef2c05aebe1c3650513fa7f6a360810e (patch)
tree403e765cc1e7983bd2015f90b962b00e84f8f2e4
parent2ded515ba32c01359200d3fe725b0fd062cb1634 (diff)
downloadlua-language-server-dd1c80a8ef2c05aebe1c3650513fa7f6a360810e.zip
暂且先这样
-rw-r--r--server/src/matcher/vm.lua16
-rw-r--r--server/test/hover/init.lua2
-rw-r--r--server/test/type_inference/init.lua4
3 files changed, 19 insertions, 3 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index b1d303a9..2d1f025a 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -414,12 +414,12 @@ function mt:call(func, values)
if lib then
if lib.args then
for i, arg in ipairs(lib.args) do
- self:inference(self:getFunctionArg(func, i), arg.type)
+ self:inference(self:getFunctionArg(func, i), arg.type or 'any')
end
end
if lib.returns then
for i, rtn in ipairs(lib.returns) do
- self:inference(self:getFunctionReturns(func, i), rtn.type)
+ self:inference(self:getFunctionReturns(func, i), rtn.type or 'any')
end
end
if lib.special then
@@ -461,6 +461,9 @@ function mt:setFunctionReturn(func, index, value)
end
function mt:getFunctionReturns(func, i)
+ if func.maxReturns and i and func.maxReturns < i then
+ return self:createValue('nil')
+ end
if not func.returns then
func.returns = {
type = 'list',
@@ -532,9 +535,18 @@ function mt:getLibValue(lib, parentType, v)
elseif tp == 'function' then
value = self:createValue('function')
if lib.returns then
+ local dots
for i, rtn in ipairs(lib.returns) do
self:setFunctionReturn(value, i, self:getLibValue(rtn, parentType))
+ if rtn.type == '...' then
+ dots = true
+ end
end
+ if not dots then
+ value.maxReturns = #lib.returns
+ end
+ else
+ value.maxReturns = 0
end
if lib.args then
local values = {}
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 8bbde91f..31e604f3 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -152,7 +152,7 @@ TEST[[
TEST [[
local <?v?> = collectgarbage()
]]
-"nil v"
+"any v"
TEST [[
local type
diff --git a/server/test/type_inference/init.lua b/server/test/type_inference/init.lua
index 820d00c9..9f5887f1 100644
--- a/server/test/type_inference/init.lua
+++ b/server/test/type_inference/init.lua
@@ -177,3 +177,7 @@ TEST 'integer' [[
for <?i?> in ipairs(t) do
end
]]
+
+TEST 'any' [[
+local <?x?> = next()
+]]