diff options
-rw-r--r-- | script/core/generic.lua | 5 | ||||
-rw-r--r-- | script/core/linker.lua | 8 | ||||
-rw-r--r-- | script/core/searcher.lua | 4 | ||||
-rw-r--r-- | script/parser/ast.lua | 6 | ||||
-rw-r--r-- | test/definition/luadoc.lua | 70 |
5 files changed, 82 insertions, 11 deletions
diff --git a/script/core/generic.lua b/script/core/generic.lua index 9f203e69..53ced59c 100644 --- a/script/core/generic.lua +++ b/script/core/generic.lua @@ -157,7 +157,7 @@ local function buildValues(closure) if doc.type == 'doc.param' then local extends = doc.extends local index = extends.paramIndex - local param = params[index] + local param = params and params[index] closure.params[index] = param and createValue(closure, extends, function (road, key, proto) buildValue(road, key, proto, param, upvalues) end) or extends @@ -191,9 +191,6 @@ end function m.createClosure(proto, call) local protoFunction, parentClosure if proto.type == 'function' then - if not proto.args or #proto.args == 0 then - return nil - end protoFunction = proto elseif proto.type == 'generic.value' then protoFunction = proto.proto diff --git a/script/core/linker.lua b/script/core/linker.lua index f2a9e572..622561db 100644 --- a/script/core/linker.lua +++ b/script/core/linker.lua @@ -117,12 +117,18 @@ local function getKey(source) end return source.start, nil elseif source.type == 'doc.class.name' - or source.type == 'doc.type.name' or source.type == 'doc.alias.name' or source.type == 'doc.extends.name' or source.type == 'doc.see.name' then local name = source[1] return name, nil + elseif source.type == 'doc.type.name' then + if source.typeGeneric then + return source.start, nil + else + local name = source[1] + return name, nil + end elseif source.type == 'doc.class' or source.type == 'doc.type' or source.type == 'doc.alias' diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 54d95859..fc1c08d1 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -174,7 +174,6 @@ function m.searchRefsByID(status, uri, expect, mode) status.id = expect local mark = status.mark - local queueIndex = 0 local callStack = {} @@ -186,11 +185,10 @@ function m.searchRefsByID(status, uri, expect, mode) else fieldLen = 0 end - if mark[id] and mark[id] <= fieldLen then + if mark[id] and ((mark[id] < fieldLen) or fieldLen == 0) then return end mark[id] = fieldLen - queueIndex = queueIndex + 1 searchStep(id, field) end diff --git a/script/parser/ast.lua b/script/parser/ast.lua index 47093f0e..b2a9fa37 100644 --- a/script/parser/ast.lua +++ b/script/parser/ast.lua @@ -1461,9 +1461,9 @@ local Defs = { if func then local call = createCall(exp, func.finish + 1, exp.finish) if #exp == 0 then - exp[1] = getSelect(func, 1) - exp[2] = getSelect(func, 2) - exp[3] = getSelect(func, 3) + exp[1] = getSelect(func, 2) + exp[2] = getSelect(func, 3) + exp[3] = getSelect(func, 4) end call.node = func call.start = inA diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua index fe6d1e21..e6827d65 100644 --- a/test/definition/luadoc.lua +++ b/test/definition/luadoc.lua @@ -427,11 +427,81 @@ local <?<!c!>?> = f(b) ]] TEST [[ +---@generic V +---@return fun(t: V[]):V +local function f() end + +---@class A +local <!a!> + +---@type A[] +local b + +local f2 = f() + +local <?<!c!>?> = f2(b) +]] + +TEST [[ +---@generic T, V +---@param t T +---@return fun(t: V[]):V +---@return T +local function f(t) end + +---@class A +local <!a!> + +---@type A[] +local b + +local f2, c = f(b) + +local <?<!d!>?> = f2(c) +]] + +TEST [[ +---@class C +local <!v1!> + +---@generic V, T +---@param t T +---@return fun(t: V): V +---@return T +local function iterator(t) end + +for <!v!> in iterator(v1) do + print(<?v?>) +end +]] + +TEST [[ ---@class C +local <!v!> + +---@type C local <!v1!> ---@generic V, T ---@param t T +---@return fun(t: V): V +---@return T +local function iterator(t) end + +for <!v!> in iterator(v1) do + print(<?v?>) +end +]] + +TEST [[ +---@class C +local <!v!> + +---@type C[] +local v1 + +---@generic V, T +---@param t T ---@return fun(t: V[]): V ---@return T local function iterator(t) end |