Skip to content

Commit

Permalink
fix/adapt docgen
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Dec 19, 2023
1 parent 39ab56b commit 6ac6c85
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 30 deletions.
16 changes: 10 additions & 6 deletions compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,9 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags, nonEx
symbolOrIdEnc = encodeUrl(symbolOrId, usePlus = false)
deprecationMsg = genDeprecationMsg(d, pragmaNode)
rstLangSymbol = toLangSymbol(k, n, cleanPlainSymbol)
symNameNode =
if nameNode.kind == nkPostfix: nameNode[1]
else: nameNode

# we generate anchors automatically for subsequent use in doc comments
let lineinfo = rstast.TLineInfo(
Expand Down Expand Up @@ -1122,18 +1125,19 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags, nonEx
let external = d.destFile.AbsoluteFile.relativeTo(d.conf.outDir, '/').changeFileExt(HtmlExt).string

var attype = ""
if k in routineKinds and nameNode.kind == nkSym:
if k in routineKinds and symNameNode.kind == nkSym:
let att = attachToType(d, nameNode.sym)
if att != nil:
attype = esc(d.target, att.name.s)
elif k == skType and nameNode.kind == nkSym and nameNode.sym.typ.kind in {tyEnum, tyBool}:
let etyp = nameNode.sym.typ
elif k == skType and symNameNode.kind == nkSym and
symNameNode.sym.typ.kind in {tyEnum, tyBool}:
let etyp = symNameNode.sym.typ
for e in etyp.n:
if e.sym.kind != skEnumField: continue
let plain = renderPlainSymbolName(e)
let symbolOrId = d.newUniquePlainSymbol(plain)
setIndexTerm(d[], ieNim, htmlFile = external, id = symbolOrId,
term = plain, linkTitle = nameNode.sym.name.s & '.' & plain,
term = plain, linkTitle = symNameNode.sym.name.s & '.' & plain,
linkDesc = xmltree.escape(getPlainDocstring(e).docstringSummary),
line = n.info.line.int)

Expand All @@ -1154,8 +1158,8 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags, nonEx
linkTitle = detailedName,
linkDesc = xmltree.escape(plainDocstring.docstringSummary),
line = n.info.line.int)
if k == skType and nameNode.kind == nkSym:
d.types.strTableAdd nameNode.sym
if k == skType and symNameNode.kind == nkSym:
d.types.strTableAdd symNameNode.sym

proc genJsonItem(d: PDoc, n, nameNode: PNode, k: TSymKind, nonExports = false): JsonItem =
if not isVisible(d, nameNode): return
Expand Down
4 changes: 2 additions & 2 deletions nimdoc/extlinks/project/expected/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h1 class="title">nimdoc/extlinks/project/main</h1>
<details open>
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#A" title="A = object">A</a></li>
<li><a class="reference" href="#A" title="A* = object">A</a></li>

</ul>
</details>
Expand Down Expand Up @@ -95,7 +95,7 @@ <h1><a class="toc-backref" href="#6">Imports</a></h1>
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="A">
<dt><pre><a href="main.html#A"><span class="Identifier">A</span></a> <span class="Other">=</span> <span class="Keyword">object</span>
<dt><pre><a href="main.html#A"><span class="Identifier">A</span></a><span class="Operator">*</span> <span class="Other">=</span> <span class="Keyword">object</span>
</pre></dt>
<dd>

Expand Down
4 changes: 2 additions & 2 deletions nimdoc/extlinks/project/expected/sub/submodule.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h1 class="title">nimdoc/extlinks/project/sub/submodule</h1>
<details open>
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#submoduleInt" title="submoduleInt = distinct int">submoduleInt</a></li>
<li><a class="reference" href="#submoduleInt" title="submoduleInt* = distinct int">submoduleInt</a></li>

</ul>
</details>
Expand Down Expand Up @@ -84,7 +84,7 @@ <h1 class="title">nimdoc/extlinks/project/sub/submodule</h1>
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="submoduleInt">
<dt><pre><a href="submodule.html#submoduleInt"><span class="Identifier">submoduleInt</span></a> <span class="Other">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int</span></pre></dt>
<dt><pre><a href="submodule.html#submoduleInt"><span class="Identifier">submoduleInt</span></a><span class="Operator">*</span> <span class="Other">=</span> <span class="Keyword">distinct</span> <span class="Identifier">int</span></pre></dt>
<dd>


Expand Down
8 changes: 4 additions & 4 deletions nimdoc/testproject/expected/subdir/subdir_b/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ <h1 class="title">subdir/subdir_b/utils</h1>
<details open>
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#G" title="G[T] = object">G</a></li>
<li><a class="reference" href="#SomeType" title="SomeType = enum
<li><a class="reference" href="#G" title="G*[T] = object">G</a></li>
<li><a class="reference" href="#SomeType" title="SomeType* = enum
enumValueA, enumValueB, enumValueC">SomeType</a></li>

</ul>
Expand Down Expand Up @@ -253,7 +253,7 @@ <h2><a class="toc-backref" id="pandoc-markdown-symbols-documentation" href="#pan
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="G">
<dt><pre><a href="utils.html#G"><span class="Identifier">G</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span>
<dt><pre><a href="utils.html#G"><span class="Identifier">G</span></a><span class="Operator">*</span><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <span class="Keyword">object</span>
</pre></dt>
<dd>

Expand All @@ -262,7 +262,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</dd>
</div>
<div id="SomeType">
<dt><pre><a href="utils.html#SomeType"><span class="Identifier">SomeType</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
<dt><pre><a href="utils.html#SomeType"><span class="Identifier">SomeType</span></a><span class="Operator">*</span> <span class="Other">=</span> <span class="Keyword">enum</span>
<span class="Identifier">enumValueA</span><span class="Other">,</span> <span class="Identifier">enumValueB</span><span class="Other">,</span> <span class="Identifier">enumValueC</span></pre></dt>
<dd>

Expand Down
32 changes: 16 additions & 16 deletions nimdoc/testproject/expected/testproject.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,27 @@ <h1 class="title">testproject</h1>
<details open>
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
<ul class="simple simple-toc-section">
<li><a class="reference" href="#A" title="A {.inject.} = enum
<li><a class="reference" href="#A" title="A* {.inject.} = enum
aA">A</a></li>
<li><a class="reference" href="#AnotherObject" title="AnotherObject = object
<li><a class="reference" href="#AnotherObject" title="AnotherObject* = object
case x*: bool
of true:
y*: proc (x: string)
of false:">AnotherObject</a></li>
<li><a class="reference" href="#B" title="B {.inject.} = enum
<li><a class="reference" href="#B" title="B* {.inject.} = enum
bB">B</a></li>
<li><a class="reference" href="#Foo" title="Foo = enum
<li><a class="reference" href="#Foo" title="Foo* = enum
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
<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>
<li><a class="reference" href="#Shapes" title="Shapes = enum
<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
<li><a class="reference" href="#T19396" title="T19396* = object
a*: int">T19396</a></li>

</ul>
Expand Down Expand Up @@ -368,7 +368,7 @@ <h1><a class="toc-backref" href="#6">Imports</a></h1>
<h1><a class="toc-backref" href="#7">Types</a></h1>
<dl class="item">
<div id="A">
<dt><pre><a href="testproject.html#A"><span class="Identifier">A</span></a> {.<span class="Identifier">inject</span>.} <span class="Other">=</span> <span class="Keyword">enum</span>
<dt><pre><a href="testproject.html#A"><span class="Identifier">A</span></a><span class="Operator">*</span> {.<span class="Identifier">inject</span>.} <span class="Other">=</span> <span class="Keyword">enum</span>
<span class="Identifier">aA</span></pre></dt>
<dd>

Expand All @@ -377,7 +377,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</dd>
</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>
<dt><pre><a href="testproject.html#AnotherObject"><span class="Identifier">AnotherObject</span></a><span class="Operator">*</span> <span class="Other">=</span> <span class="Keyword">object</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="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>
Expand All @@ -392,7 +392,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</dd>
</div>
<div id="B">
<dt><pre><a href="testproject.html#B"><span class="Identifier">B</span></a> {.<span class="Identifier">inject</span>.} <span class="Other">=</span> <span class="Keyword">enum</span>
<dt><pre><a href="testproject.html#B"><span class="Identifier">B</span></a><span class="Operator">*</span> {.<span class="Identifier">inject</span>.} <span class="Other">=</span> <span class="Keyword">enum</span>
<span class="Identifier">bB</span></pre></dt>
<dd>

Expand All @@ -401,7 +401,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</dd>
</div>
<div id="Foo">
<dt><pre><a href="testproject.html#Foo"><span class="Identifier">Foo</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
<dt><pre><a href="testproject.html#Foo"><span class="Identifier">Foo</span></a><span class="Operator">*</span> <span class="Other">=</span> <span class="Keyword">enum</span>
<span class="Identifier">enumValueA2</span></pre></dt>
<dd>

Expand All @@ -410,7 +410,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</dd>
</div>
<div id="FooBuzz">
<dt><pre><a href="testproject.html#FooBuzz"><span class="Identifier">FooBuzz</span></a> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">&quot;FooBuzz msg&quot;</span></span>.} <span class="Other">=</span> <span class="Identifier">int</span></pre></dt>
<dt><pre><a href="testproject.html#FooBuzz"><span class="Identifier">FooBuzz</span></a><span class="Operator">*</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">&quot;FooBuzz msg&quot;</span></span>.} <span class="Other">=</span> <span class="Identifier">int</span></pre></dt>
<dd>
<div class="deprecation-message">
<b>Deprecated:</b> FooBuzz msg
Expand All @@ -421,7 +421,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</dd>
</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>
<dt><pre><a href="testproject.html#MyObject"><span class="Identifier">MyObject</span></a><span class="Operator">*</span> <span class="Other">=</span> <span class="Keyword">object</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>
Expand All @@ -432,7 +432,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</dd>
</div>
<div id="Shapes">
<dt><pre><a href="testproject.html#Shapes"><span class="Identifier">Shapes</span></a> <span class="Other">=</span> <span class="Keyword">enum</span>
<dt><pre><a href="testproject.html#Shapes"><span class="Identifier">Shapes</span></a><span class="Operator">*</span> <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>
Expand All @@ -443,7 +443,7 @@ <h1><a class="toc-backref" href="#7">Types</a></h1>
</dd>
</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>
<dt><pre><a href="testproject.html#T19396"><span class="Identifier">T19396</span></a><span class="Operator">*</span> <span class="Other">=</span> <span class="Keyword">object</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 6ac6c85

Please sign in to comment.