summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2024-01-24 15:13:53 +0800
committer最萌小汐 <sumneko@hotmail.com>2024-01-24 15:15:21 +0800
commit89edbfaffe7dbbcc4fda2c22fa64ae078fd6ead9 (patch)
tree4a5fb8de64feb8c38649e68d9fa07d157dd45edc
parentdcacfe7c899de9232bc51f9f8f055423823f2edb (diff)
downloadlua-language-server-89edbfaffe7dbbcc4fda2c22fa64ae078fd6ead9.zip
Revert "Merge pull request #2481 from fesily/automatic-derivation-function-param-type"
This reverts commit 34319c7990cba47ddc00e77aabfccbb923f84e26, reversing changes made to ef7157c450254b0ee447960b0cb06d6f1b0dbaaa.
-rw-r--r--script/vm/compiler.lua21
-rw-r--r--test/diagnostics/await-in-sync.lua2
-rw-r--r--test/diagnostics/redundant-parameter.lua2
-rw-r--r--test/hover/init.lua4
-rw-r--r--test/signature/init.lua14
5 files changed, 29 insertions, 14 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 0fe2efe8..2253c83a 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -1121,9 +1121,24 @@ local function compileLocal(source)
end
if source.parent.type == 'funcargs' and not hasMarkDoc and not hasMarkParam then
local func = source.parent.parent
- local vmPlugin = plugin.getVmPlugin(guide.getUri(source))
- local hasDocArg = vmPlugin and vmPlugin.OnCompileFunctionParam(compileFunctionParam, func, source)
- or compileFunctionParam(func, source)
+ -- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number
+ local funcNode = vm.compileNode(func)
+ local hasDocArg
+ for n in funcNode:eachObject() do
+ if n.type == 'doc.type.function' then
+ for index, arg in ipairs(n.args) do
+ if func.args[index] == source then
+ local argNode = vm.compileNode(arg)
+ for an in argNode:eachObject() do
+ if an.type ~= 'doc.generic.name' then
+ vm.setNode(source, an)
+ end
+ end
+ hasDocArg = true
+ end
+ end
+ end
+ end
if not hasDocArg then
vm.setNode(source, vm.declareGlobal('type', 'any'))
end
diff --git a/test/diagnostics/await-in-sync.lua b/test/diagnostics/await-in-sync.lua
index 7647f2eb..323c1113 100644
--- a/test/diagnostics/await-in-sync.lua
+++ b/test/diagnostics/await-in-sync.lua
@@ -119,7 +119,7 @@ end
TEST [[
local function f(cb)
- <!cb!>()
+ cb()
end
local function af()
diff --git a/test/diagnostics/redundant-parameter.lua b/test/diagnostics/redundant-parameter.lua
index 520a6381..fabe3340 100644
--- a/test/diagnostics/redundant-parameter.lua
+++ b/test/diagnostics/redundant-parameter.lua
@@ -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)
]]
diff --git a/test/hover/init.lua b/test/hover/init.lua
index 851443ec..63220a59 100644
--- a/test/hover/init.lua
+++ b/test/hover/init.lua
@@ -276,7 +276,7 @@ function string.lower(s: string|number)
-> string
]]
--- 根据传入值推测参数类型
+-- 不根据传入值推测参数类型
TEST [[
local function x(a, ...)
end
@@ -284,7 +284,7 @@ end
<?x?>(1, 2, 3, 4, 5, 6, 7)
]]
[[
-function x(a: integer, ...any)
+function x(a: any, ...any)
]]
TEST [[
diff --git a/test/signature/init.lua b/test/signature/init.lua
index 2bf4b824..f46ce017 100644
--- a/test/signature/init.lua
+++ b/test/signature/init.lua
@@ -88,7 +88,7 @@ end
x(1, 2, 3, <??>
]]
-{'function x(a: integer, <!...any!>)'}
+{'function x(a: any, <!...any!>)'}
TEST [[
(''):sub(<??>
@@ -106,7 +106,7 @@ end
f(1, 'string<??>')
]]
-{'function f(a: integer, <!b: string!>, c: any)'}
+{'function f(a: any, <!b: any!>, c: any)'}
TEST [[
pcall(function () <??> end)
@@ -156,7 +156,7 @@ end
f({},<??>)
]]
-{'function f(a: table, <!b: any!>, c: any)'}
+{'function f(a: any, <!b: any!>, c: any)'}
TEST [[
for _ in pairs(<??>) do
@@ -188,7 +188,7 @@ end
x( aaaa <??>, 2)
]]
-{"function x(<!a: any!>, b: integer)"}
+{"function x(<!a: any!>, b: any)"}
TEST [[
local function x(a, b)
@@ -196,7 +196,7 @@ end
x(<??> aaaa , 2)
]]
-{'function x(<!a: any!>, b: integer)'}
+{'function x(<!a: any!>, b: any)'}
TEST [[
local function x(a, b)
@@ -204,7 +204,7 @@ end
x(aaaa ,<??> 2)
]]
-{'function x(a: any, <!b: integer!>)'}
+{'function x(a: any, <!b: any!>)'}
TEST [[
local function x(a, b)
@@ -212,7 +212,7 @@ end
x(aaaa , 2 <??>)
]]
-{'function x(a: any, <!b: integer!>)'}
+{'function x(a: any, <!b: any!>)'}
TEST [[
local fooC