Skip to content

Commit

Permalink
fix nim-lang#15702, show enum fields documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
narimiran committed Oct 30, 2020
1 parent d8fb237 commit 26816d5
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
3 changes: 2 additions & 1 deletion compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
e.typ = result
e.position = int(counter)
let symNode = newSymNode(e)
if optNimV1Emulation notin c.config.globalOptions and identToReplace != nil:
if optNimV1Emulation notin c.config.globalOptions and identToReplace != nil and
c.config.cmd != cmdDoc: # A hack to produce documentation for enum fields.

This comment has been minimized.

Copy link
@timotheecour

timotheecour Oct 30, 2020

that's a simple fix but it's also going to bite us later, since macros involving enum now behave differently for nim doc vs nim c which can have unintended consequences.
The proper fix should be to fix docgen.

identToReplace[] = symNode
if e.position == 0: hasNull = true
if result.sym != nil and sfExported in result.sym.flags:
Expand Down
15 changes: 15 additions & 0 deletions nimdoc/testproject/expected/testproject.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ <h1 class="title">testproject</h1>
<li><a class="reference" href="#Foo"
title="Foo = enum
enumValueA2">Foo</a></li>
<li><a class="reference" href="#Shapes"
title="Shapes = enum
Circle, ## A circle
Triangle, ## A three-sided shape
Rectangle ## A four-sided shape">Shapes</a></li>

</ul>
</li>
Expand Down Expand Up @@ -406,6 +411,16 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>



</dd>
<a id="Shapes"></a>
<dt><pre><a href="testproject.html#Shapes"><span class="Identifier">Shapes</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
<span class="Identifier">Circle</span><span class="Other">,</span> <span class="Comment">## A circle</span>
<span class="Identifier">Triangle</span><span class="Other">,</span> <span class="Comment">## A three-sided shape</span>
<span class="Identifier">Rectangle</span> <span class="Comment">## A four-sided shape</span></pre></dt>
<dd>

Some shapes.

</dd>

</dl></div>
Expand Down
4 changes: 4 additions & 0 deletions nimdoc/testproject/expected/testproject.idx
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ asyncFun1 testproject.html#asyncFun1 testproject: asyncFun1(): Future[int]
asyncFun2 testproject.html#asyncFun2 testproject: asyncFun2(): owned(Future[void])
asyncFun3 testproject.html#asyncFun3 testproject: asyncFun3(): owned(Future[void])
testNimDocTrailingExample testproject.html#testNimDocTrailingExample.t testproject: testNimDocTrailingExample()
Circle testproject.html#Circle Shapes.Circle
Triangle testproject.html#Triangle Shapes.Triangle
Rectangle testproject.html#Rectangle Shapes.Rectangle
Shapes testproject.html#Shapes testproject: Shapes
16 changes: 16 additions & 0 deletions nimdoc/testproject/expected/theindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ <h1 class="title">Index</h1>
<li><a class="reference external"
data-doc-search-tag="testproject: C_D" href="testproject.html#C_D">testproject: C_D</a></li>
</ul></dd>
<dt><a name="Circle" href="#Circle"><span>Circle:</span></a></dt><dd><ul class="simple">
<li><a class="reference external"
data-doc-search-tag="Shapes.Circle" href="testproject.html#Circle">Shapes.Circle</a></li>
</ul></dd>
<dt><a name="c_nonexistant" href="#c_nonexistant"><span>c_nonexistant:</span></a></dt><dd><ul class="simple">
<li><a class="reference external"
data-doc-search-tag="testproject: c_nonexistant(frmt: cstring): cint" href="testproject.html#c_nonexistant%2Ccstring">testproject: c_nonexistant(frmt: cstring): cint</a></li>
Expand Down Expand Up @@ -220,6 +224,14 @@ <h1 class="title">Index</h1>
<li><a class="reference external"
data-doc-search-tag="testproject: p1()" href="testproject.html#p1">testproject: p1()</a></li>
</ul></dd>
<dt><a name="Rectangle" href="#Rectangle"><span>Rectangle:</span></a></dt><dd><ul class="simple">
<li><a class="reference external"
data-doc-search-tag="Shapes.Rectangle" href="testproject.html#Rectangle">Shapes.Rectangle</a></li>
</ul></dd>
<dt><a name="Shapes" href="#Shapes"><span>Shapes:</span></a></dt><dd><ul class="simple">
<li><a class="reference external"
data-doc-search-tag="testproject: Shapes" href="testproject.html#Shapes">testproject: Shapes</a></li>
</ul></dd>
<dt><a name="someFunc" href="#someFunc"><span>someFunc:</span></a></dt><dd><ul class="simple">
<li><a class="reference external"
data-doc-search-tag="testproject: someFunc()" href="testproject.html#someFunc">testproject: someFunc()</a></li>
Expand All @@ -236,6 +248,10 @@ <h1 class="title">Index</h1>
<li><a class="reference external"
data-doc-search-tag="testproject: testNimDocTrailingExample()" href="testproject.html#testNimDocTrailingExample.t">testproject: testNimDocTrailingExample()</a></li>
</ul></dd>
<dt><a name="Triangle" href="#Triangle"><span>Triangle:</span></a></dt><dd><ul class="simple">
<li><a class="reference external"
data-doc-search-tag="Shapes.Triangle" href="testproject.html#Triangle">Shapes.Triangle</a></li>
</ul></dd>
<dt><a name="tripleStrLitTest" href="#tripleStrLitTest"><span>tripleStrLitTest:</span></a></dt><dd><ul class="simple">
<li><a class="reference external"
data-doc-search-tag="testproject: tripleStrLitTest()" href="testproject.html#tripleStrLitTest">testproject: tripleStrLitTest()</a></li>
Expand Down
10 changes: 9 additions & 1 deletion nimdoc/testproject/testproject.nim
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,12 @@ when true:
# where runnableExamples would not show if there was not at least 2 "\n" after
# the last character of runnableExamples
runnableExamples:
discard 2
discard 2

when true: # issue #15702
type
Shapes* = enum
## Some shapes.
Circle, ## A circle
Triangle, ## A three-sided shape
Rectangle ## A four-sided shape

0 comments on commit 26816d5

Please sign in to comment.