diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/core/noder.lua | 22 | ||||
-rw-r--r-- | test/type_inference/init.lua | 22 |
3 files changed, 41 insertions, 4 deletions
diff --git a/changelog.md b/changelog.md index d2595a4f..272387e6 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ * `FIX` [#805](https://github.com/sumneko/lua-language-server/issues/805) * `FIX` [#806](https://github.com/sumneko/lua-language-server/issues/806) * `FIX` [#807](https://github.com/sumneko/lua-language-server/issues/807) +* `FIX` [#809](https://github.com/sumneko/lua-language-server/issues/809) ## 2.4.9 `2021-11-18` diff --git a/script/core/noder.lua b/script/core/noder.lua index 59c103e8..ab8d2aa4 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -150,11 +150,23 @@ local function getFieldEventName(field) if not docFunc or docFunc.type ~= 'doc.type.function' then return nil end - local firstArg = docFunc.args and #docFunc.args == 2 and docFunc.args[1] + local firstArg = docFunc.args and docFunc.args[1] if not firstArg then return nil end - local secondArg = docFunc.args[2] + local secondArg + if firstArg.name[1] == 'self' then + firstArg = docFunc.args[2] + if not firstArg then + return nil + end + secondArg = docFunc.args[3] + else + secondArg = docFunc.args[2] + end + if not secondArg then + return + end local firstType = firstArg.extends if not firstType then return nil @@ -799,8 +811,10 @@ local function compileCallParam(noders, call, sourceID) if not nodeID then return end + local methodIndex = 0 if node.type == 'getmethod' then fixIndex = fixIndex + 1 + methodIndex = 1 end local eventNodeID for firstIndex, callArg in ipairs(call.args) do @@ -820,7 +834,7 @@ local function compileCallParam(noders, call, sourceID) local paramID = sformat('%s%s%s%s%s' , nodeID , PARAM_INDEX - , firstIndex + , firstIndex + methodIndex , PARAM_INDEX , secondIndex ) @@ -829,7 +843,7 @@ local function compileCallParam(noders, call, sourceID) local eventParamID = sformat('%s%s%s%s%s' , eventNodeID , PARAM_INDEX - , firstIndex + , firstIndex + methodIndex , PARAM_INDEX , secondIndex ) diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 1a07b807..80eae39d 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -926,6 +926,17 @@ TEST 'integer' [[ --- @field on fun(eventName: '"won"', cb: fun(s: string)) local emit = {} +emit.on("died", function (<?i?>) +end) +]] + +TEST 'integer' [[ +--- @class Emit +--- @field on fun(self: Emit, eventName: string, cb: function) +--- @field on fun(self: Emit, eventName: '"died"', cb: fun(i: integer)) +--- @field on fun(self: Emit, eventName: '"won"', cb: fun(s: string)) +local emit = {} + emit:on("died", function (<?i?>) end) ]] @@ -992,3 +1003,14 @@ TEST 'Test' [[ ---@class Test _G.<?Test?> = {} ]] + +TEST 'integer' [[ +local mt = {} + +---@param callback fun(i: integer) +function mt:loop(callback) end + +mt:loop(function (<?i?>) + +end) +]] |