diff options
author | fesily <fesil@foxmail.com> | 2024-01-17 19:28:26 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-17 19:28:26 +0800 |
commit | dd49a6dd6afc35a14fba3b675a2d9f1ee2bb7ca4 (patch) | |
tree | c338f21a68e1efc2b86c4746cdd81ff5892c6431 | |
parent | 326a033a816f0bd5dcca6aeea1443935ee5a9e3c (diff) | |
parent | 34319c7990cba47ddc00e77aabfccbb923f84e26 (diff) | |
download | lua-language-server-dd49a6dd6afc35a14fba3b675a2d9f1ee2bb7ca4.zip |
Merge branch 'master' into plugin-OnNodeCompileFunctionParam
-rw-r--r-- | script/vm/compiler.lua | 29 | ||||
-rw-r--r-- | test/diagnostics/await-in-sync.lua | 2 | ||||
-rw-r--r-- | test/diagnostics/redundant-parameter.lua | 2 | ||||
-rw-r--r-- | test/hover/init.lua | 4 | ||||
-rw-r--r-- | test/signature/init.lua | 14 |
5 files changed, 40 insertions, 11 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 6b8b76cd..4621006e 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1091,6 +1091,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 local suc, node = plugin.dispatch("OnNodeCompileFunctionParam", guide.getUri(source), source) if suc and node then diff --git a/test/diagnostics/await-in-sync.lua b/test/diagnostics/await-in-sync.lua index 323c1113..7647f2eb 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 fabe3340..520a6381 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 63220a59..851443ec 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: any, ...any) +function x(a: integer, ...any) ]] TEST [[ diff --git a/test/signature/init.lua b/test/signature/init.lua index f46ce017..2bf4b824 100644 --- a/test/signature/init.lua +++ b/test/signature/init.lua @@ -88,7 +88,7 @@ end x(1, 2, 3, <??> ]] -{'function x(a: any, <!...any!>)'} +{'function x(a: integer, <!...any!>)'} TEST [[ (''):sub(<??> @@ -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) @@ -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 @@ -188,7 +188,7 @@ end x( aaaa <??>, 2) ]] -{"function x(<!a: any!>, b: any)"} +{"function x(<!a: any!>, b: integer)"} TEST [[ local function x(a, b) @@ -196,7 +196,7 @@ end x(<??> aaaa , 2) ]] -{'function x(<!a: any!>, b: any)'} +{'function x(<!a: any!>, b: integer)'} TEST [[ local function x(a, b) @@ -204,7 +204,7 @@ end x(aaaa ,<??> 2) ]] -{'function x(a: any, <!b: any!>)'} +{'function x(a: any, <!b: integer!>)'} TEST [[ local function x(a, b) @@ -212,7 +212,7 @@ end x(aaaa , 2 <??>) ]] -{'function x(a: any, <!b: any!>)'} +{'function x(a: any, <!b: integer!>)'} TEST [[ local fooC |