diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2023-06-13 20:20:46 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2023-06-13 20:20:46 +0800 |
commit | fa287e75c9d4ad2ebabc1a6ceec5bbc9393a33b8 (patch) | |
tree | a22dbd9116007d08efa48f77cea147af1502fb9d | |
parent | 4081b303684b95ec27fd833a1cd10978d4ad5e10 (diff) | |
download | lua-language-server-fa287e75c9d4ad2ebabc1a6ceec5bbc9393a33b8.zip |
bind overloads
fix #2083
-rw-r--r-- | .vscode/launch.json | 6 | ||||
-rw-r--r-- | changelog.md | 6 | ||||
-rw-r--r-- | script/core/diagnostics/param-type-mismatch.lua | 18 | ||||
-rw-r--r-- | script/vm/compiler.lua | 6 | ||||
-rw-r--r-- | test/diagnostics/type-check.lua | 8 |
5 files changed, 31 insertions, 13 deletions
diff --git a/.vscode/launch.json b/.vscode/launch.json index b80e7f49..efc6d602 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,12 +9,10 @@ "stopOnEntry": false, "program": "${workspaceRoot}/test.lua", "luaexe": "${workspaceFolder}/bin/lua-language-server", - "cpath": null, - "arg": [ - ], "luaVersion": "5.4", "sourceCoding": "utf8", - "console": "internalConsole", + "console": "integratedTerminal", + "internalConsoleOptions": "openOnSessionStart", "outputCapture": [ "print", "stderr", diff --git a/changelog.md b/changelog.md index ff35198a..2b570ab5 100644 --- a/changelog.md +++ b/changelog.md @@ -3,9 +3,13 @@ ## 3.6.22 * `FIX` [#2038] * `FIX` [#2042] +* `FIX` [#2062] +* `FIX` [#2083] -[#2042]: https://github.com/LuaLS/lua-language-server/issues/2042 [#2038]: https://github.com/LuaLS/lua-language-server/issues/2038 +[#2042]: https://github.com/LuaLS/lua-language-server/issues/2042 +[#2062]: https://github.com/LuaLS/lua-language-server/issues/2062 +[#2083]: https://github.com/LuaLS/lua-language-server/issues/2083 ## 3.6.21 `2023-5-24` diff --git a/script/core/diagnostics/param-type-mismatch.lua b/script/core/diagnostics/param-type-mismatch.lua index da39c5e1..acbf9c8c 100644 --- a/script/core/diagnostics/param-type-mismatch.lua +++ b/script/core/diagnostics/param-type-mismatch.lua @@ -32,26 +32,28 @@ end ---@param funcNode vm.node ---@param i integer +---@param uri uri ---@return vm.node? -local function getDefNode(funcNode, i) +local function getDefNode(funcNode, i, uri) local defNode = vm.createNode() - for f in funcNode:eachObject() do - if f.type == 'function' - or f.type == 'doc.type.function' then - local param = f.args and f.args[i] + for src in funcNode:eachObject() do + if src.type == 'function' + or src.type == 'doc.type.function' then + local param = src.args and src.args[i] if param then defNode:merge(vm.compileNode(param)) if param[1] == '...' then defNode:addOptional() end - - expandGenerics(defNode) end end end if defNode:isEmpty() then return nil end + + expandGenerics(defNode) + return defNode end @@ -91,7 +93,7 @@ return function (uri, callback) if not refNode then goto CONTINUE end - local defNode = getDefNode(funcNode, i) + local defNode = getDefNode(funcNode, i, uri) if not defNode then goto CONTINUE end diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 6b4636fc..cd114bd1 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -55,6 +55,9 @@ function vm.bindDocs(source) vm.setNode(source, vm.compileNode(ast)) return true end + if doc.type == 'doc.overload' then + vm.setNode(source, vm.compileNode(doc)) + end end return false end @@ -1020,6 +1023,7 @@ local function compileLocal(source) vm.setNode(source, vm.compileNode(source.value)) end end + -- function x.y(self, ...) --> function x:y(...) if source[1] == 'self' and not hasMarkDoc @@ -1031,6 +1035,7 @@ local function compileLocal(source) vm.setNode(source, vm.compileNode(setfield.node)) end end + if source.parent.type == 'funcargs' and not hasMarkDoc and not hasMarkParam then local func = source.parent.parent -- local call ---@type fun(f: fun(x: number));call(function (x) end) --> x -> number @@ -1055,6 +1060,7 @@ local function compileLocal(source) vm.setNode(source, vm.declareGlobal('type', 'any')) end end + -- for x in ... do if source.parent.type == 'in' then compileForVars(source.parent, source) diff --git a/test/diagnostics/type-check.lua b/test/diagnostics/type-check.lua index 18e7190d..dd9d1198 100644 --- a/test/diagnostics/type-check.lua +++ b/test/diagnostics/type-check.lua @@ -1255,6 +1255,14 @@ local var func(var) ]] +TEST [[ +---@class MyClass +---@overload fun(x : string) : MyClass +local MyClass = {} + +local w = MyClass(<!1!>) +]] + config.remove(nil, 'Lua.diagnostics.disable', 'unused-local') config.remove(nil, 'Lua.diagnostics.disable', 'unused-function') config.remove(nil, 'Lua.diagnostics.disable', 'undefined-global') |