Skip to content

Commit

Permalink
render fields anyway
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Dec 22, 2023
1 parent 8acb12c commit 69111aa
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
14 changes: 10 additions & 4 deletions compiler/renderer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1334,14 +1334,20 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) =
put(g, tkColon, ":")
gsub(g, n, bodyPos)
of nkIdentDefs:
# Skip if this is a property in a type and its not exported
# (While also not allowing rendering of non exported fields)
if ObjectDef in g.inside and (not n[0].isExported() and renderNonExportedFields notin g.flags):
return
var exclFlags: TRenderFlags = {}
if ObjectDef in g.inside:
if not n[0].isExported() and renderNonExportedFields notin g.flags:
# Skip if this is a property in a type and its not exported
# (While also not allowing rendering of non exported fields)
return
# render postfix for object fields:
exclFlags = g.flags * {renderNoPostfix}
# We render the identDef without being inside the section incase we render something like
# y: proc (x: string) # (We wouldn't want to check if x is exported)
g.outside(ObjectDef):
g.flags.excl(exclFlags)
gcomma(g, n, 0, -3)
g.flags.incl(exclFlags)
if n.len >= 2 and n[^2].kind != nkEmpty:
putWithSpace(g, tkColon, ":")
gsub(g, n[^2], c)
Expand Down
20 changes: 10 additions & 10 deletions nimdoc/testproject/expected/testproject.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ <h1 class="title">testproject</h1>
<li><a class="reference" href="#A" title="A {.inject.} = enum
aA">A</a></li>
<li><a class="reference" href="#AnotherObject" title="AnotherObject = object
case x: bool
case x*: bool
of true:
y: proc (x: string)
y*: proc (x: string)
of false:">AnotherObject</a></li>
<li><a class="reference" href="#B" title="B {.inject.} = enum
Expand All @@ -68,14 +68,14 @@ <h1 class="title">testproject</h1>
enumValueA2">Foo</a></li>
<li><a class="reference" href="#FooBuzz" title="FooBuzz {.deprecated: &quot;FooBuzz msg&quot;.} = int">FooBuzz</a></li>
<li><a class="reference" href="#MyObject" title="MyObject = object
someString: string ## This is a string
annotated {.somePragma.}: string ## This is an annotated string">MyObject</a></li>
someString*: string ## This is a string
annotated* {.somePragma.}: string ## This is an annotated string">MyObject</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>
<li><a class="reference" href="#T19396" title="T19396 = object
a: int">T19396</a></li>
a*: int">T19396</a></li>

</ul>
</details>
Expand Down Expand Up @@ -378,9 +378,9 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</div>
<div id="AnotherObject">
<dt><pre><a href="testproject.html#AnotherObject"><span class="Identifier">AnotherObject</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
<span class="Keyword">case</span> <span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">bool</span>
<span class="Keyword">case</span> <span class="Identifier">x</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">bool</span>
<span class="Keyword">of</span> <span class="Identifier">true</span><span class="Other">:</span>
<span class="Identifier">y</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span>
<span class="Identifier">y</span><span class="Operator">*</span><span class="Other">:</span> <span class="Keyword">proc</span> <span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">string</span><span class="Other">)</span>

<span class="Keyword">of</span> <span class="Identifier">false</span><span class="Other">:</span>

Expand Down Expand Up @@ -422,8 +422,8 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</div>
<div id="MyObject">
<dt><pre><a href="testproject.html#MyObject"><span class="Identifier">MyObject</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
<span class="Identifier">someString</span><span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is a string</span>
<span class="Identifier">annotated</span> {.<span class="Identifier">somePragma</span>.}<span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is an annotated string</span>
<span class="Identifier">someString</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is a string</span>
<span class="Identifier">annotated</span><span class="Operator">*</span> {.<span class="Identifier">somePragma</span>.}<span class="Other">:</span> <span class="Identifier">string</span> <span class="Comment">## This is an annotated string</span>
</pre></dt>
<dd>

Expand All @@ -444,7 +444,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</div>
<div id="T19396">
<dt><pre><a href="testproject.html#T19396"><span class="Identifier">T19396</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
<span class="Identifier">a</span><span class="Other">:</span> <span class="Identifier">int</span>
<span class="Identifier">a</span><span class="Operator">*</span><span class="Other">:</span> <span class="Identifier">int</span>
</pre></dt>
<dd>

Expand Down

0 comments on commit 69111aa

Please sign in to comment.