Skip to content

Commit 04c3ccf

Browse files
committed
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 ziglang#23614
1 parent 86d3546 commit 04c3ccf

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/docs/main.js

+1
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@
599599
const members = namespaceMembers(decl_index, false).slice();
600600
const fields = declFields(decl_index).slice();
601601
renderNamespace(decl_index, members, fields);
602+
renderDocTests(decl_index);
602603
}
603604

604605
function operatorCompare(a, b) {

lib/docs/wasm/Walk.zig

+7
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,13 @@ fn struct_decl(
537537
try w.file.get().scopes.putNoClobber(gpa, node, &namespace.base);
538538
try w.scanDecls(namespace, container_decl.ast.members);
539539

540+
// TODO: Support for doctests on file-as-a-struct types without using
541+
// the filename to find the associated test.
542+
const stem = std.fs.path.stem(w.file.path());
543+
if (namespace.doctests.get(stem)) |doctest_node| {
544+
try w.file.get().doctests.put(gpa, parent_decl.get().ast_node, doctest_node);
545+
}
546+
540547
for (container_decl.ast.members) |member| switch (ast.nodeTag(member)) {
541548
.container_field_init,
542549
.container_field_align,

0 commit comments

Comments
 (0)