Skip to content

autodoc: Lookup file-as-a-struct doctests using the stem of the filename #23615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/docs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions lib/docs/wasm/Walk.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment on lines +540 to +541
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

@squeek502 squeek502 Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#23614 is the relevant issue until this is merged. If this is merged, I'll open a separate issue for this TODO.

To be clear, this TODO would be relevant for something like:

// Foo.zig

const Bar = @This();

test Bar {
    // ...
}

After this PR, this doctest will still fail to be found, since it only looks for Foo (based on the filename).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant is that the TODO should be replaced with an issue link.

Copy link
Collaborator Author

@squeek502 squeek502 Apr 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's awkward because that issue is sort of in limbo--it only needs to exist if this PR is merged.

Happy to open an issue and replace the TODO with a link if I can get confirmation that this PR is going to be merged.

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,
Expand Down
Loading