-
Notifications
You must be signed in to change notification settings - Fork 23
Description
proposal
make docgen automatically add import foo in the generated html for a top-level runnableExamples inside module foo;
in fact this is what is done by the part of docgen that does for running the code, see https://github.com/nim-lang/Nim/pull/17282/files#diff-2471f1aaac2c91ed83e0317b1b0b322fc719a4cb431de811baa8e350dade283fR531, except that:
- unlike what's done in docgen though, it'll need to show a canonical relative path, not an absolute path; this requires fix #16973 ; nim doc now shows correct, canonical import name in title Nim#16999 which I still need to finalize,
- unlike what's done in docgen, we probably only want to show imports for top-level runnableExamples
pros
easier to copy paste and edit, matches what's actually being run
note
to avoid generating too much noise, this proposal only concerns top-level runnableExamples, so that
doAssert toUpperAscii("FooBar!") == "FOOBAR!"will remain unaffected instead of generating:
import std/strutils
doAssert toUpperAscii("FooBar!") == "FOOBAR!"which would just obfuscate (a little bit) the code; it should be clear from context that import std/strutils is needed for runnableExamples attached to a symbol.
it's not perfect, because some large but non top-level runnableExamples could benefit from showing such import, but these are rare; eg: https://nim-lang.github.io/Nim/sugar.html#collect.m%2Cuntyped
links
refs nim-lang/Nim#17203 (comment)
refs https://forum.nim-lang.org/t/7622#48410
pr_fix_rfc_17282_runnableExamples_show_import