Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions script/vm/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,35 @@ local function compileLocal(source)
end
end
end
if not hasDocArg
and func.parent.type == 'local' then
local refs = func.parent.ref
local findCall
if refs then
for i, ref in ipairs(refs) do
if ref.parent.type == 'call' then
findCall = ref.parent
break
end
end
end
if findCall and findCall.args then
local index
for i, arg in ipairs(source.parent) do
if arg == source then
index = i
break
end
end
if index then
local callerArg = findCall.args[index]
if callerArg then
hasDocArg = true
vm.setNode(source, vm.compileNode(callerArg))
end
end
end
end
if not hasDocArg then
vm.setNode(source, vm.declareGlobal('type', 'any'))
end
Expand Down
2 changes: 1 addition & 1 deletion test/diagnostics/await-in-sync.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ end

TEST [[
local function f(cb)
cb()
<!cb!>()
end

local function af()
Expand Down
2 changes: 1 addition & 1 deletion test/diagnostics/redundant-parameter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ print(1, 2, 3, 4, 5)

TEST [[
local function f(callback)
callback(1, 2, 3)
callback(<!1!>, <!2!>, <!3!>)
end
f(function () end)
]]
Expand Down
4 changes: 2 additions & 2 deletions test/hover/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,15 @@ function string.lower(s: string|number)
-> string
]]

-- 不根据传入值推测参数类型
-- 根据传入值推测参数类型
TEST [[
local function x(a, ...)
end

<?x?>(1, 2, 3, 4, 5, 6, 7)
]]
[[
function x(a: any, ...any)
function x(a: integer, ...any)
]]

TEST [[
Expand Down
14 changes: 7 additions & 7 deletions test/signature/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ end

x(1, 2, 3, <??>
]]
{'function x(a: any, <!...any!>)'}
{'function x(a: integer, <!...any!>)'}

TEST [[
(''):sub(<??>
Expand All @@ -106,7 +106,7 @@ end

f(1, 'string<??>')
]]
{'function f(a: any, <!b: any!>, c: any)'}
{'function f(a: integer, <!b: string!>, c: any)'}

TEST [[
pcall(function () <??> end)
Expand Down Expand Up @@ -156,7 +156,7 @@ end

f({},<??>)
]]
{'function f(a: any, <!b: any!>, c: any)'}
{'function f(a: table, <!b: any!>, c: any)'}

TEST [[
for _ in pairs(<??>) do
Expand Down Expand Up @@ -188,31 +188,31 @@ end

x( aaaa <??>, 2)
]]
{"function x(<!a: any!>, b: any)"}
{"function x(<!a: any!>, b: integer)"}

TEST [[
local function x(a, b)
end

x(<??> aaaa , 2)
]]
{'function x(<!a: any!>, b: any)'}
{'function x(<!a: any!>, b: integer)'}

TEST [[
local function x(a, b)
end

x(aaaa ,<??> 2)
]]
{'function x(a: any, <!b: any!>)'}
{'function x(a: any, <!b: integer!>)'}

TEST [[
local function x(a, b)
end

x(aaaa , 2 <??>)
]]
{'function x(a: any, <!b: any!>)'}
{'function x(a: any, <!b: integer!>)'}

TEST [[
local fooC
Expand Down