summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-11-24 17:33:32 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-11-24 17:33:32 +0800
commitaf0eba42be501bbbde95b15bcc8da191c21a9c1c (patch)
tree1613814ccf4de03249be581e93e82bc5079de225
parent051df431b8f5bca83c129bba57960b371babb85d (diff)
downloadlua-language-server-af0eba42be501bbbde95b15bcc8da191c21a9c1c.zip
doc.type.function support vararg
-rw-r--r--script/core/hover/arg.lua17
-rw-r--r--script/parser/luadoc.lua60
-rw-r--r--test/hover/init.lua8
3 files changed, 58 insertions, 27 deletions
diff --git a/script/core/hover/arg.lua b/script/core/hover/arg.lua
index 9cd19f02..c0518993 100644
--- a/script/core/hover/arg.lua
+++ b/script/core/hover/arg.lua
@@ -51,11 +51,18 @@ local function asDocFunction(source)
for i = 1, #source.args do
local arg = source.args[i]
local name = arg.name[1]
- args[i] = ('%s%s: %s'):format(
- name,
- arg.optional and '?' or '',
- vm.getInferType(arg.extends)
- )
+ if arg.extends then
+ args[i] = ('%s%s: %s'):format(
+ name,
+ arg.optional and '?' or '',
+ vm.getInferType(arg.extends)
+ )
+ else
+ args[i] = ('%s%s'):format(
+ name,
+ arg.optional and '?' or ''
+ )
+ end
end
return table.concat(args, ', ')
end
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua
index 2f29d4eb..2b7866e1 100644
--- a/script/parser/luadoc.lua
+++ b/script/parser/luadoc.lua
@@ -304,31 +304,47 @@ local function parseTypeUnitFunction()
type = 'doc.type.arg',
parent = typeUnit,
}
- arg.name = parseName('doc.type.name', arg)
- if not arg.name then
- pushError {
- type = 'LUADOC_MISS_ARG_NAME',
- start = getFinish(),
+ if checkToken('symbol', '...', 1) then
+ nextToken()
+ local vararg = {
+ type = 'doc.type.name',
+ start = getStart(),
finish = getFinish(),
+ parent = arg,
+ [1] = '...',
}
- break
- end
- if not arg.start then
- arg.start = arg.name.start
- end
- if checkToken('symbol', '?', 1) then
- nextToken()
- arg.optional = true
- end
- arg.finish = getFinish()
- if not nextSymbolOrError(':') then
- break
- end
- arg.extends = parseType(arg)
- if not arg.extends then
- break
+ arg.name = vararg
+ if not arg.start then
+ arg.start = arg.name.start
+ end
+ arg.finish = getFinish()
+ else
+ arg.name = parseName('doc.type.name', arg)
+ if not arg.name then
+ pushError {
+ type = 'LUADOC_MISS_ARG_NAME',
+ start = getFinish(),
+ finish = getFinish(),
+ }
+ break
+ end
+ if not arg.start then
+ arg.start = arg.name.start
+ end
+ if checkToken('symbol', '?', 1) then
+ nextToken()
+ arg.optional = true
+ end
+ arg.finish = getFinish()
+ if not nextSymbolOrError(':') then
+ break
+ end
+ arg.extends = parseType(arg)
+ if not arg.extends then
+ break
+ end
+ arg.finish = getFinish()
end
- arg.finish = getFinish()
typeUnit.args[#typeUnit.args+1] = arg
if checkToken('symbol', ',', 1) then
nextToken()
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 7ed794d1..cd3313cb 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -1418,3 +1418,11 @@ local c: C {
field: any,
}
]]
+
+TEST [[
+---@param callback fun(x: integer, ...)
+local function f(<?callback?>) end
+]]
+[[
+function (x: integer, ...)
+]]