From 04c3ccf877c157d5db3c4cea8cecd677f75cddea Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Sat, 19 Apr 2025 17:38:30 -0700 Subject: [PATCH] autodoc: Lookup file-as-a-struct doctests using the stem of the filename This is not a perfect solution and relies on the convention that file-as-a-struct types have the same file name as the type name. Fixes #23614 --- lib/docs/main.js | 1 + lib/docs/wasm/Walk.zig | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/lib/docs/main.js b/lib/docs/main.js index 330b51ba49d1..08b3426159cb 100644 --- a/lib/docs/main.js +++ b/lib/docs/main.js @@ -599,6 +599,7 @@ const members = namespaceMembers(decl_index, false).slice(); const fields = declFields(decl_index).slice(); renderNamespace(decl_index, members, fields); + renderDocTests(decl_index); } function operatorCompare(a, b) { diff --git a/lib/docs/wasm/Walk.zig b/lib/docs/wasm/Walk.zig index e3884f6271e8..6f06585905b1 100644 --- a/lib/docs/wasm/Walk.zig +++ b/lib/docs/wasm/Walk.zig @@ -537,6 +537,13 @@ fn struct_decl( try w.file.get().scopes.putNoClobber(gpa, node, &namespace.base); try w.scanDecls(namespace, container_decl.ast.members); + // TODO: Support for doctests on file-as-a-struct types without using + // the filename to find the associated test. + const stem = std.fs.path.stem(w.file.path()); + if (namespace.doctests.get(stem)) |doctest_node| { + try w.file.get().doctests.put(gpa, parent_decl.get().ast_node, doctest_node); + } + for (container_decl.ast.members) |member| switch (ast.nodeTag(member)) { .container_field_init, .container_field_align,