-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
autodoc: include entire code on line in source #19301
Conversation
@@ -540,7 +542,9 @@ export fn decl_doctest_html(decl_index: Decl.Index) String { | |||
return String.init(""); | |||
|
|||
string_result.clearRetainingCapacity(); | |||
file_source_html(decl.file, &string_result, doctest_ast_node, .{}) catch |err| { | |||
file_source_html(decl.file, &string_result, doctest_ast_node, .{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds the same behavior to rendering doctests.
imo it should print option 2. just the decl and whitespace trimmed while preserving indentation. |
Hmm, I think we disagree on what would be the actual "Source Code." I think it would be weird to not include all of the original lines because we may make snippets show up like in the Zig guides with line numbers. Although, the current way doesn't show any of the tokens on the last line after the terminator which would have to be changed to follow that definition. |
badf3fd
to
778ab76
Compare
9d8895f
to
75c94f7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch, @sno2. This discussion has convinced me that simply including the entire line is not good enough, and the original required behavior I specified in #19293 is the required behavior.
Case 1
Input:
fn add(a: u32, b: u32) u32 {
return a + b;
}
Expected Output:
fn add(a: u32, b: u32) u32 {
return a + b;
}
Case 2
Input:
const a = 1; fn add(a: u32, b: u32) u32 {
return a + b;
}
Expected Output:
fn add(a: u32, b: u32) u32 {
return a + b;
}
Case 3
Input:
fn add(a: u32, b: u32) u32 {
return a + b;
}
Expected Output:
fn add(a: u32, b: u32) u32 {
return a + b;
}
Case 4
Input:
const a = 1; fn add(a: u32, b: u32) u32 {
return a + b;
}
Expected Output:
fn add(a: u32, b: u32) u32 {
return a + b;
}
Note that those last two cases are planned to become syntax errors:
imo the existence of zig fmt's api in the stdlib should mean that with: const a = 1; fn add(a: u32, b: u32) u32 {
return a + b;
} when viewing the source of fn add(a: u32, b: u32) u32 {
return a + b;
} |
If anyone else would like to work on this- be my guest. I have exams to study for until halfway through next week so I will be busy until then. Will re-open next week. |
Closes #19293
I took the easy route and just add the entire line's contents. This fixes the noted issue:
I am unsure if I introduced what you were warning against. Do you want
to render as itself, or
or
This implementation assumes you want the first option.