summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/parser/guide.lua57
-rw-r--r--script-beta/parser/luadoc.lua3
-rw-r--r--test-beta/hover/init.lua9
3 files changed, 64 insertions, 5 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index 35295a27..0decb789 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -2414,6 +2414,22 @@ function m.isSameValue(status, a, b)
return true
end
+function m.inferCheckLiteralTableWithDocVararg(status, source)
+ if #source ~= 1 then
+ return
+ end
+ local vararg = source[1]
+ if vararg.type ~= 'varargs' then
+ return
+ end
+ local results = m.getVarargDocType(source)
+ status.results[#status.results+1] = {
+ type = m.viewInferType(results) .. '[]',
+ source = source,
+ }
+ return true
+end
+
function m.inferCheckLiteral(status, source)
if source.type == 'string' then
status.results = m.allocInfer {
@@ -2459,6 +2475,9 @@ function m.inferCheckLiteral(status, source)
}
return true
elseif source.type == 'table' then
+ if m.inferCheckLiteralTableWithDocVararg(status, source) then
+ return true
+ end
status.results = m.allocInfer {
type = 'table',
source = source,
@@ -2552,7 +2571,45 @@ function m.inferCheckDoc(status, source)
end
end
+function m.getVarargDocType(source)
+ local func = m.getParentFunction(source)
+ if not func then
+ return
+ end
+ if not func.args then
+ return
+ end
+ for _, arg in ipairs(func.args) do
+ if arg.type == '...' then
+ if arg.bindDocs then
+ for _, doc in ipairs(arg.bindDocs) do
+ if doc.type == 'doc.vararg' then
+ return m.getDocTypeNames(doc.vararg)
+ end
+ end
+ end
+ end
+ end
+end
+
+function m.inferCheckUpDocOfVararg(status, source)
+ if not source.vararg then
+ return
+ end
+ local results = m.getVarargDocType(source)
+ if not results then
+ return
+ end
+ for _, res in ipairs(results) do
+ status.results[#status.results+1] = res
+ end
+ return true
+end
+
function m.inferCheckUpDoc(status, source)
+ if m.inferCheckUpDocOfVararg(status, source) then
+ return true
+ end
while source.type == 'select' or source.type == 'call' do
local parent = source.parent
if parent.type == 'local'
diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua
index 68fef250..72974d28 100644
--- a/script-beta/parser/luadoc.lua
+++ b/script-beta/parser/luadoc.lua
@@ -728,7 +728,8 @@ local function bindDoc(state, lns, binded)
or src.type == 'setindex'
or src.type == 'tablefield'
or src.type == 'tableindex'
- or src.type == 'function' then
+ or src.type == 'function'
+ or src.type == '...' then
src.bindDocs = binded
bindSources[#bindSources+1] = src
end
diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua
index a21c7416..c4f6cb92 100644
--- a/test-beta/hover/init.lua
+++ b/test-beta/hover/init.lua
@@ -1009,7 +1009,6 @@ local <?r?> = f(1)
local r: integer = 1
]]
-do return end
TEST [[
---@param x number
---@param y boolean
@@ -1028,19 +1027,21 @@ end
f(1, 2, 3)
]]
[[
-local x: *Class = 2
+local x: Class
]]
TEST [[
---@vararg Class
local function f(...)
- local _, <?x?> = ...
+ local <?t?> = {...}
end
+f(1, 2, 3)
]]
[[
-local x: *Class {}
+local t: Class[]
]]
+do return end
TEST [[
---@type string[]
local <?x?>