-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
runnableExamples should preserve source code doc comments, strings, and (maybe) formatting #8871
Comments
+1 on this one, some more examples: func swapEndian*(T: typedesc[SomeNumber], buf: var openArray[byte],
startIndex: Natural) {.inline, since: (1,1).} =
## Swaps the byte order of a number stored as a byte sequence in `buf`
## starting at `startIndex`. The type of the number must be passed in as an
## argument.
runnableExamples:
var buf: array[6, byte]
buf[0] = 0xff
buf[1] = 0xca
buf[2] = 0xfe
buf[3] = 0x42
swapEndian(uint16, buf, 1)
doAssert buf[0] == 0xff
doAssert buf[1] == 0xfe
doAssert buf[2] == 0xca
doAssert buf[3] == 0x42 And here's the result. Note the literals have been reformatted, there's extra leading zeroes, which doesn't make much sense as these are bytes, and they're uppercased: Ideally, we should just take the original text, strip the left margin, and just insert it into the documentation unchanged. We shouldn't parse it into AST and the regenerate the source from that, we're losing information that way. Just taking the text as it is seems to be the easiest thing to do anyway. |
my thoughts as well; the code is being parsed/run anyways with |
Well, I don't think there should be a doc comment/non-doc comment distinction in the runnableExamples blocks anyway, so I think it's a non-issue. The rule would be that the text would appear in the documentation verbatim, and that's the end of it, it's simple. |
I'd even propose a |
…, litterals, and all formatting
…, litterals, and all formatting
…, litterals, and all formatting
…, litterals, and all formatting
…, litterals, and all formatting
…, litterals, and all formatting
…, litterals, and all formatting
…, litterals, and all formatting
…als, and all formatting; other bug fix (#14439) * fix #8871 runnableExamples now preserves source code comments, litterals, and all formatting * remove orig deadcode from getAllRunnableExamplesImpl * fix expected examples * add test to close #14473 * correctly handle regular comments before 1st token inside runnableExamples * add test to answer #14439 (comment) * update tests
renders as:
\'
in"\'foo" , although not incorrect, is not needed and the way it's written in the source (
"'foo"`)should be preservedline_doc_comment
is not rendered##
with empty comment (belowbar
) is wrongly insertedthese are correct:
##
)bar
which is not a doc comment is not preserved (useful to distinguish what shd end up in docs vs not)links
The text was updated successfully, but these errors were encountered: