diff --git a/lib/docs/main.js b/lib/docs/main.js index d37dea5200..f9d5f0383b 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -482,13 +482,13 @@ var zigAnalysis; continue; } -// if ("as" in value.expr) { -// value = { -// typeRef: zigAnalysis.exprs[value.expr.as.typeRefArg], -// expr: zigAnalysis.exprs[value.expr.as.exprArg], -// }; -// continue; -// } + if ("as" in value.expr) { + value = { + typeRef: zigAnalysis.exprs[value.expr.as.typeRefArg], + expr: zigAnalysis.exprs[value.expr.as.exprArg], + }; + continue; + } return value; @@ -1355,7 +1355,7 @@ var zigAnalysis; } case "this":{ - return "this"; + return "@This()"; } case "type": { @@ -2333,6 +2333,23 @@ var zigAnalysis; * @param {string} childName */ function findSubDecl(parentType, childName) { + { + // Generic functions + if ("value" in parentType) { + const rv = resolveValue(parentType.value); + if ("type" in rv.expr) { + const t = zigAnalysis.types[rv.expr.type]; + if (t.kind == typeKinds.Fn && t.generic_ret != null) { + const rgr = resolveValue({expr: t.generic_ret}); + if ("type" in rgr.expr) { + parentType = zigAnalysis.types[rgr.expr.type]; + } + } + } + } + } + + if (!parentType.pubDecls) return null; for (let i = 0; i < parentType.pubDecls.length; i += 1) { let declIndex = parentType.pubDecls[i]; diff --git a/src/Autodoc.zig b/src/Autodoc.zig index 9ff2010bf6..f9b15b0c2d 100644 --- a/src/Autodoc.zig +++ b/src/Autodoc.zig @@ -3885,12 +3885,32 @@ fn analyzeFunctionExtended( _ = try self.walkRef(file, scope, align_ref, false); } + // TODO: a complete version of this will probably need a scope + // in order to evaluate correctly closures around funcion + // parameters etc. + const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) { + .type => |t| blk: { + if (fn_info.body.len == 0) break :blk null; + if (t == @enumToInt(Ref.type_type)) { + break :blk try self.getGenericReturnType( + file, + scope, + fn_info.body[fn_info.body.len - 1], + ); + } else { + break :blk null; + } + }, + else => null, + }; + self.types.items[type_slot_index] = .{ .Fn = .{ .name = "todo_name func", .src = self_ast_node_index, .params = param_type_refs.items, .ret = ret_type_ref.expr, + .generic_ret = generic_ret, .is_extern = extra.data.bits.is_extern, .has_cc = extra.data.bits.has_cc, .has_align = extra.data.bits.has_align, @@ -3995,14 +4015,18 @@ fn analyzeFunction( // in order to evaluate correctly closures around funcion // parameters etc. const generic_ret: ?DocData.Expr = switch (ret_type_ref.expr) { - .type => |t| if (t == @enumToInt(Ref.type_type)) - try self.getGenericReturnType( - file, - scope, - fn_info.body[fn_info.body.len - 1], - ) - else - null, + .type => |t| blk: { + if (fn_info.body.len == 0) break :blk null; + if (t == @enumToInt(Ref.type_type)) { + break :blk try self.getGenericReturnType( + file, + scope, + fn_info.body[fn_info.body.len - 1], + ); + } else { + break :blk null; + } + }, else => null, };