Skip to content
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

docgen: anchors for procs omit params if their default values are variable names #12373

Open
Jjp137 opened this issue Oct 7, 2019 · 0 comments
Labels
Documentation Generation Related to documentation generation (but not content).

Comments

@Jjp137
Copy link
Contributor

Jjp137 commented Oct 7, 2019

If a proc has a parameter with a default value, and the default value is the name of a variable, the generated HTML anchor for that proc does not include that parameter's type.

It does not matter whether the variable was declared with let, var, or const. This issue does not occur if the default value is a literal instead of a variable name.

Example

Generate the documentation for this example with nim doc:

# Can also be 'var' or 'const'
let num = 5

proc incorrect*(x = num) =
  ## A proc with an incorrect anchor.
  discard

proc okay*(x = 5) =
  ## A proc with the expected anchor.
  discard

Current Output

Excerpt from the generated HTML:

<a id="incorrect"></a>
<dt><pre><span class="Keyword">proc</span> <a href="#incorrect"><span class="Identifier">incorrect</span></a><span class="Other">(</span><span class="Identifier">x</span> <span class="Other">=</span> <span class="Identifier">num</span><span class="Other">)</span> <span><span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span></span><span class="pragmawrap"><span class="Other">{.</span><span class="pragma"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span><span class="Other">.}</span></span></pre></dt>
<dd>

A proc with an incorrect anchor.

</dd>
<a id="okay,int"></a>
<dt><pre><span class="Keyword">proc</span> <a href="#okay%2Cint"><span class="Identifier">okay</span></a><span class="Other">(</span><span class="Identifier">x</span> <span class="Other">=</span> <span class="DecNumber">5</span><span class="Other">)</span> <span><span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span></span><span class="pragmawrap"><span class="Other">{.</span><span class="pragma"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span><span class="Other">.}</span></span></pre></dt>
<dd>

A proc with the expected anchor.

</dd>

Note that the anchor for the incorrect proc does not include the int parameter, but the okay proc does, which feels inconsistent.

Expected Output

<a id="incorrect,int"></a>
<dt><pre><span class="Keyword">proc</span> <a href="#incorrect%2Cint"><span class="Identifier">incorrect</span></a><span class="Other">(</span><span class="Identifier">x</span> <span class="Other">=</span> <span class="Identifier">num</span><span class="Other">)</span> <span><span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span></span><span class="pragmawrap"><span class="Other">{.</span><span class="pragma"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span><span class="Other">.}</span></span></pre></dt>
<dd>

A proc with an incorrect anchor.

</dd>
<a id="okay,int"></a>
<dt><pre><span class="Keyword">proc</span> <a href="#okay%2Cint"><span class="Identifier">okay</span></a><span class="Other">(</span><span class="Identifier">x</span> <span class="Other">=</span> <span class="DecNumber">5</span><span class="Other">)</span> <span><span class="Other">{</span><span class="Other pragmadots">...</span><span class="Other">}</span></span><span class="pragmawrap"><span class="Other">{.</span><span class="pragma"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span><span class="Other">.}</span></span></pre></dt>
<dd>

A proc with the expected anchor.

</dd>

The id and href attributes for the anchor tags are the important parts.

Additional Information

Output of nim -v:

Nim Compiler Version 1.0.99 [Linux: amd64]
Compiled at 2019-10-07
Copyright (c) 2006-2019 by Andreas Rumpf

git hash: 5be8e0b0883c5d88db8f24db36d114290dffcae3
active boot switches: -d:release

Also occurs with 1.0.

@andreaferretti andreaferretti added the Documentation Generation Related to documentation generation (but not content). label Oct 9, 2019
@a-mr a-mr mentioned this issue Dec 17, 2021
33 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Generation Related to documentation generation (but not content).
Projects
None yet
Development

No branches or pull requests

2 participants