-
-
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
fix #8871 runnableExamples now preserves source code comments, litterals, and all formatting; other bug fix #14439
fix #8871 runnableExamples now preserves source code comments, litterals, and all formatting; other bug fix #14439
Conversation
86a0a5e
to
ad97b77
Compare
This is awesome! Just yesterday, I noticed that runnableExamples was reformatting my manually set indentation; e.g. this rendered to https://kaushalmodi.github.io/version/#getVersion%2CopenArray%5Bstring%5D%2Cstring |
Did you consider to re-use nimpretty's approach? Also, is it time to make |
d182094
to
e38466f
Compare
@Araq PTAL (you can look at generated html for
nimpretty doesn't do syntax highlighting so the code I wrote is still needed even with reusing/calling nimpretty. This PR got a bit larger than initially because I fixed other issues (see updated note in top post) and added a lot of tests, but the part that's responsible for extracting and rendering runnableExampes (ie fixing #8871) is actually quite concise.
IMO we should completely separate the reflection part (getting postprocessed (after semcheck) AST with module infos, symbols, doc comments properly attached, runnableExamples-as-string, etc) from the rendering part (including running runnableExamples which calls nim-as-binary and doesn't need to depend on compiler sources). All rendering code should be separated from the compiler and would just consume what the 1st step produces (IR, json, PNode, etc see below though). and here's how it should work IMO: macros should be powerful enough to enable full reflection and 100% replace docgenWe can have really clean concise This is one of the uses cases I had in mind with #9560 and #8903 and I actually had a working prototype of Note: this approach invovles 0 serialization (no IR or json needed) since the macros get all they need via a NimNode for each module representing all symbols. It's then possible for user code to then convert these to whatever format needed (json, etc) or to re-do what nim doc does. other use cases for reflection beyond nim docthese could be implemented in user code via macros by exposing AST after semantic phase:
|
@timotheecour Love the idea of docgen as a macro. import macros
macro genDocs(e: typed) =
echo treeRepr e
genDocs:
include moduleWeWantToGenerateDocsFor |
I completely disagree. This idea that we can never ever reduce an AST because it might be rendered back to ascii somewhere did cost us years of implementation effort, keeps costing us effort and makes writing macros more complex. What's the benefit? A good docgen is still as hard to implement as it was before, if not harder and you'll put pressure on the Nim VM. |
@timotheecour Referring to your comment in #14473 (comment),
Yes, I just confirmed that this PR fixes the minimal example in #14473, as well as in my real project. Can you update a test case in this PR to also Thanks! |
e38466f
to
afedbaa
Compare
done. (see also: nim-lang/RFCs#231) |
friendly ping @Araq because this fixes a very recent regression that I've introduced in #14441 that prevents some runnableExamples from running; let me know if you instead want me
|
…, litterals, and all formatting
afedbaa
to
0811b41
Compare
@Araq PTAL; all points addressed and found I more corner case that i fixed (regular comments before the 1st node inside a runnableExamples are now correctly handled, ie appear as part of the doc comment) in reply to #14439 (comment)
I added some explanation inside PR code; whether it's a bug or not I'm not sure, but it seems inconsistent that you have: proc someType*(): int =
## foo
result = 3
=> this is weird
result =
## foo
3;
proc someType*(): int =
## foo
3
=> this is fine
## foo
result = 3; IMO the sane behavior is for transf to transform the 1st case into the following instead: ## foo
result = 3; This has very strong echoes of #14420 (comment) EDIT: simplified further in #14701 |
\r
renders as\c
#9345getAllRunnableExamples
nim doc ..
on a user project is attempting to run runnableExamples from stdlibs, and failing incorrectly [devel] [regression] #14473 (similar/same as above point)testNimDocTrailingExample
, becausenumLines
is inclusivemost imporantly:
so now both #8871 and #8871 as can be seen in by comparing
nim doc --outdir:htmldocs --project nimdoc/testproject/testproject.nim
:for #8871
right before #14441:
after this PR:
=> we're now preserving formatting exactly (in particular we don't skip comments, change litterals and change indentation etc)
and for #8871
right before #14441:
after this PR:
=> we're now not skipping doc comments (C) after the 1st runnableExamples (R) so if you have CRCRC you end up with CRCRC instead of CRR; also we're now preserving ordering