summaryrefslogtreecommitdiff
path: root/script
diff options
context:
space:
mode:
Diffstat (limited to 'script')
-rw-r--r--script/core/completion/completion.lua3
-rw-r--r--script/core/hover/args.lua2
-rw-r--r--script/core/hover/return.lua12
-rw-r--r--script/parser/luadoc.lua23
-rw-r--r--script/vm/compiler.lua7
-rw-r--r--script/vm/function.lua2
-rw-r--r--script/vm/infer.lua22
7 files changed, 63 insertions, 8 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua
index 392c21ca..243a9a76 100644
--- a/script/core/completion/completion.lua
+++ b/script/core/completion/completion.lua
@@ -165,7 +165,8 @@ local function buildFunctionSnip(source, value, oop)
truncated = true
end
for i = #args, 1, -1 do
- if args[i]:match('^%s*[^?]+%?:') then
+ if args[i]:match('^%s*[^?]+%?:')
+ or args[i]:match('^%.%.%.') then
table.remove(args)
truncated = true
else
diff --git a/script/core/hover/args.lua b/script/core/hover/args.lua
index 21e7c00f..321fb081 100644
--- a/script/core/hover/args.lua
+++ b/script/core/hover/args.lua
@@ -32,7 +32,7 @@ local function asFunction(source)
vm.getInfer(argNode):view(guide.getUri(source), 'any')
)
elseif arg.type == '...' then
- args[#args+1] = ('%s: %s'):format(
+ args[#args+1] = ('%s%s'):format(
'...',
vm.getInfer(arg):view(guide.getUri(source), 'any')
)
diff --git a/script/core/hover/return.lua b/script/core/hover/return.lua
index 7f96b282..b496990b 100644
--- a/script/core/hover/return.lua
+++ b/script/core/hover/return.lua
@@ -63,7 +63,10 @@ local function asFunction(source)
for i = 1, num do
local rtn = vm.getReturnOfFunction(source, i)
local doc = docs[i]
- local name = doc and doc.name and doc.name[1] and (doc.name[1] .. ': ')
+ local name = doc and doc.name and doc.name[1]
+ if name and name ~= '...' then
+ name = name .. ': '
+ end
local text = rtn and ('%s%s'):format(
name or '',
vm.getInfer(rtn):view(guide.getUri(source))
@@ -85,6 +88,13 @@ local function asDocFunction(source)
local returns = {}
for i, rtn in ipairs(source.returns) do
local rtnText = vm.getInfer(rtn):view(guide.getUri(source))
+ if rtn.name then
+ if rtn.name[1] == '...' then
+ rtnText = rtn.name[1] .. rtnText
+ else
+ rtnText = rtn.name[1] .. ': ' .. rtnText
+ end
+ end
if i == 1 then
returns[#returns+1] = (' -> %s'):format(rtnText)
else
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 06cd5511..392b476f 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -434,11 +434,31 @@ local function parseTypeUnitFunction(parent)
end
if checkToken('symbol', ':', 1) then
nextToken()
+ local needCloseParen
+ if checkToken('symbol', '(', 1) then
+ nextToken()
+ needCloseParen = true
+ end
while true do
+ local name
+ try(function ()
+ local returnName = parseName('doc.return.name', typeUnit)
+ or parseDots('doc.return.name', typeUnit)
+ if not returnName then
+ return false
+ end
+ if checkToken('symbol', ':', 1) then
+ nextToken()
+ name = returnName
+ return true
+ end
+ return false
+ end)
local rtn = parseType(typeUnit)
if not rtn then
break
end
+ rtn.name = name
if checkToken('symbol', '?', 1) then
nextToken()
rtn.optional = true
@@ -450,6 +470,9 @@ local function parseTypeUnitFunction(parent)
break
end
end
+ if needCloseParen then
+ nextSymbolOrError ')'
+ end
end
typeUnit.finish = getFinish()
return typeUnit
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 00c8170c..46f6d0e9 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -479,7 +479,12 @@ function vm.getReturnOfFunction(func, index)
if func.type == 'doc.type.function' then
local rtn = func.returns[index]
if not rtn then
- return nil
+ local lastReturn = func.returns[#func.returns]
+ if lastReturn and lastReturn.name and lastReturn.name[1] == '...' then
+ rtn = lastReturn
+ else
+ return nil
+ end
end
local sign = getObjectSign(func)
if not sign then
diff --git a/script/vm/function.lua b/script/vm/function.lua
index bdb70faf..f992845f 100644
--- a/script/vm/function.lua
+++ b/script/vm/function.lua
@@ -113,7 +113,7 @@ function vm.countReturnsOfFunction(func, mark)
end
end
end
- if lastReturn then
+ if lastReturn then
if lastReturn.types[1][1] == '...' then
dmax = math.huge
end
diff --git a/script/vm/infer.lua b/script/vm/infer.lua
index d6c4da44..25165de6 100644
--- a/script/vm/infer.lua
+++ b/script/vm/infer.lua
@@ -155,20 +155,36 @@ local viewNodeSwitch = util.switch()
argNode = argNode:copy()
argNode:removeOptional()
end
- args[i] = string.format('%s%s: %s'
+ args[i] = string.format('%s%s%s%s'
, arg.name[1]
, isOptional and '?' or ''
+ , arg.name[1] == '...' and '' or ': '
, vm.getInfer(argNode):view(uri)
)
end
if #args > 0 then
argView = table.concat(args, ', ')
end
+ local needReturnParen
for i, ret in ipairs(source.returns) do
- rets[i] = vm.getInfer(ret):view(uri)
+ local retType = vm.getInfer(ret):view(uri)
+ if ret.name then
+ if ret.name[1] == '...' then
+ rets[i] = ('%s%s'):format(ret.name[1], retType)
+ else
+ needReturnParen = true
+ rets[i] = ('%s: %s'):format(ret.name[1], retType)
+ end
+ else
+ rets[i] = retType
+ end
end
if #rets > 0 then
- regView = ':' .. table.concat(rets, ', ')
+ if needReturnParen then
+ regView = (':(%s)'):format(table.concat(rets, ', '))
+ else
+ regView = (':%s'):format(table.concat(rets, ', '))
+ end
end
return ('fun(%s)%s'):format(argView, regView)
end)