diff options
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/core/signature.lua | 39 | ||||
-rw-r--r-- | test/signature/init.lua | 28 |
3 files changed, 68 insertions, 2 deletions
diff --git a/changelog.md b/changelog.md index ebd197b8..d81f082e 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,8 @@ # changelog +## 3.6.23 +* `CHG` signature: narrow by inputed literal + ## 3.6.22 `2023-6-14` * `FIX` [#2038] diff --git a/script/core/signature.lua b/script/core/signature.lua index 63b0cd0d..98018b21 100644 --- a/script/core/signature.lua +++ b/script/core/signature.lua @@ -89,6 +89,39 @@ local function makeOneSignature(source, oop, index) } end +local function isEventNotMatch(call, src) + if not call.args or not src.args then + return false + end + local literal, index + for i = 1, 2 do + if not call.args[i] then + break + end + literal = guide.getLiteral(call.args[i]) + if literal then + index = i + break + end + end + if not literal then + return false + end + local event = src.args[index] + if not event or event.type ~= 'doc.type.arg' then + return false + end + if not event.extends + or #event.extends.types ~= 1 then + return false + end + local eventLiteral = event.extends.types[1] and guide.getLiteral(event.extends.types[1]) + if eventLiteral == nil then + return false + end + return eventLiteral ~= literal +end + ---@async local function makeSignatures(text, call, pos) local func = call.node @@ -139,7 +172,8 @@ local function makeSignatures(text, call, pos) for src in node:eachObject() do if (src.type == 'function' and not vm.isVarargFunctionWithOverloads(src)) or src.type == 'doc.type.function' then - if not mark[src] then + if not mark[src] + and not isEventNotMatch(call, src) then mark[src] = true signs[#signs+1] = makeOneSignature(src, oop, index) end @@ -149,7 +183,8 @@ local function makeSignatures(text, call, pos) if set.type == 'doc.class' then for _, overload in ipairs(set.calls) do local f = overload.overload - if not mark[f] then + if not mark[f] + and not isEventNotMatch(call, src) then mark[f] = true signs[#signs+1] = makeOneSignature(f, oop, index) end diff --git a/test/signature/init.lua b/test/signature/init.lua index 4089bd2e..f46ce017 100644 --- a/test/signature/init.lua +++ b/test/signature/init.lua @@ -344,3 +344,31 @@ f(1, 2<??>) { 'function f(a: 😅, <!b: integer!>)', } + +TEST [[ +---@class A +---@field event fun(self: self, ev: "onChat", c: string) +---@field event fun(self: self, ev: "onTimer", t: integer) + +---@type A +local t + +t:event("onChat", <??>) +]] +{ +'(method) (ev: "onChat", <!c: string!>)', +} + +TEST [[ +---@class A +---@field event fun(self: self, ev: "onChat", c: string) +---@field event fun(self: self, ev: "onTimer", t: integer) + +---@type A +local t + +t:event("onTimer", <??>) +]] +{ +'(method) (ev: "onTimer", <!t: integer!>)', +} |