mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-18 17:08:32 +00:00
nim doc now correctly renders deprecated pragmas for routines and types (#18515)
This commit is contained in:
@@ -1168,6 +1168,37 @@ template `[]=`*(n: Indexable, i: int; x: Indexable) = n.sons[i] = x
|
||||
template `[]`*(n: Indexable, i: BackwardsIndex): Indexable = n[n.len - i.int]
|
||||
template `[]=`*(n: Indexable, i: BackwardsIndex; x: Indexable) = n[n.len - i.int] = x
|
||||
|
||||
proc getDeclPragma*(n: PNode): PNode =
|
||||
## return the `nkPragma` node for declaration `n`, or `nil` if no pragma was found.
|
||||
## Currently only supports routineDefs + {nkTypeDef}.
|
||||
case n.kind
|
||||
of routineDefs:
|
||||
if n[pragmasPos].kind != nkEmpty: result = n[pragmasPos]
|
||||
of nkTypeDef:
|
||||
#[
|
||||
type F3*{.deprecated: "x3".} = int
|
||||
|
||||
TypeSection
|
||||
TypeDef
|
||||
PragmaExpr
|
||||
Postfix
|
||||
Ident "*"
|
||||
Ident "F3"
|
||||
Pragma
|
||||
ExprColonExpr
|
||||
Ident "deprecated"
|
||||
StrLit "x3"
|
||||
Empty
|
||||
Ident "int"
|
||||
]#
|
||||
if n[0].kind == nkPragmaExpr:
|
||||
result = n[0][1]
|
||||
else:
|
||||
# support as needed for `nkIdentDefs` etc.
|
||||
result = nil
|
||||
if result != nil:
|
||||
assert result.kind == nkPragma, $(result.kind, n.kind)
|
||||
|
||||
when defined(useNodeIds):
|
||||
const nodeIdToDebug* = -1 # 2322968
|
||||
var gNodeId: int
|
||||
|
||||
@@ -764,14 +764,6 @@ proc complexName(k: TSymKind, n: PNode, baseName: string): string =
|
||||
result.add(defaultParamSeparator)
|
||||
result.add(params)
|
||||
|
||||
proc isCallable(n: PNode): bool =
|
||||
## Returns true if `n` contains a callable node.
|
||||
case n.kind
|
||||
of nkProcDef, nkMethodDef, nkIteratorDef, nkMacroDef, nkTemplateDef,
|
||||
nkConverterDef, nkFuncDef: result = true
|
||||
else:
|
||||
result = false
|
||||
|
||||
proc docstringSummary(rstText: string): string =
|
||||
## Returns just the first line or a brief chunk of text from a rst string.
|
||||
##
|
||||
@@ -862,9 +854,8 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
|
||||
break
|
||||
plainName.add(literal)
|
||||
|
||||
var pragmaNode: PNode = nil
|
||||
if n.isCallable and n[pragmasPos].kind != nkEmpty:
|
||||
pragmaNode = findPragma(n[pragmasPos], wDeprecated)
|
||||
var pragmaNode = getDeclPragma(n)
|
||||
if pragmaNode != nil: pragmaNode = findPragma(pragmaNode, wDeprecated)
|
||||
|
||||
inc(d.id)
|
||||
let
|
||||
@@ -920,7 +911,7 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
|
||||
# because it doesn't include object fields or documentation comments. So we
|
||||
# use the plain one for callable elements, and the complex for the rest.
|
||||
var linkTitle = changeFileExt(extractFilename(d.filename), "") & ": "
|
||||
if n.isCallable: linkTitle.add(xmltree.escape(plainName.strip))
|
||||
if n.kind in routineDefs: linkTitle.add(xmltree.escape(plainName.strip))
|
||||
else: linkTitle.add(xmltree.escape(complexSymbol.strip))
|
||||
|
||||
setIndexTerm(d[], external, symbolOrId, name, linkTitle,
|
||||
|
||||
@@ -593,8 +593,8 @@ proc isHideable(config: ConfigRef, n: PNode): bool =
|
||||
# xxx compare `ident` directly with `getIdent(cache, wRaises)`, but
|
||||
# this requires a `cache`.
|
||||
case n.kind
|
||||
of nkExprColonExpr: result = n[0].kind == nkIdent and n[0].ident.s in ["raises", "tags", "extern"]
|
||||
of nkIdent: result = n.ident.s in ["gcsafe"]
|
||||
of nkExprColonExpr: result = n[0].kind == nkIdent and n[0].ident.s in ["raises", "tags", "extern", "deprecated"]
|
||||
of nkIdent: result = n.ident.s in ["gcsafe", "deprecated"]
|
||||
else: result = false
|
||||
|
||||
proc gcommaAux(g: var TSrcGen, n: PNode, ind: int, start: int = 0,
|
||||
|
||||
@@ -107,7 +107,9 @@ window.addEventListener('DOMContentLoaded', main);
|
||||
<li>
|
||||
<a class="reference reference-toplevel" href="#7" id="57">Types</a>
|
||||
<ul class="simple simple-toc-section">
|
||||
<li><a class="reference" href="#A"
|
||||
<li><a class="reference" href="#FooBuzz"
|
||||
title="FooBuzz {.deprecated: "FooBuzz msg".} = int">FooBuzz</a></li>
|
||||
<li><a class="reference" href="#A"
|
||||
title="A {.inject.} = enum
|
||||
aA">A</a></li>
|
||||
<li><a class="reference" href="#B"
|
||||
@@ -445,6 +447,16 @@ window.addEventListener('DOMContentLoaded', main);
|
||||
<div class="section" id="7">
|
||||
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
||||
<dl class="item">
|
||||
<a id="FooBuzz"></a>
|
||||
<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">"FooBuzz msg"</span></span>.} <span class="Other">=</span> <span class="Identifier">int</span></pre></dt>
|
||||
<dd>
|
||||
<div class="deprecation-message">
|
||||
<b>Deprecated:</b> FooBuzz msg
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</dd>
|
||||
<a id="A"></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>
|
||||
<span class="Identifier">aA</span></pre></dt>
|
||||
@@ -544,7 +556,7 @@ This should be visible.
|
||||
|
||||
</dd>
|
||||
<a id="baz,T,T"></a>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#baz%2CT%2CT"><span class="Identifier">baz</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">a</span><span class="Other">,</span> <span class="Identifier">b</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">deprecated</span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#baz%2CT%2CT"><span class="Identifier">baz</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">a</span><span class="Other">,</span> <span class="Identifier">b</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">deprecated</span></span>.}</pre></dt>
|
||||
<dd>
|
||||
<div class="deprecation-message">
|
||||
<b>Deprecated</b>
|
||||
@@ -554,7 +566,7 @@ This is deprecated without message.
|
||||
|
||||
</dd>
|
||||
<a id="buzz,T,T"></a>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#buzz%2CT%2CT"><span class="Identifier">buzz</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">a</span><span class="Other">,</span> <span class="Identifier">b</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">"since v0.20"</span>.}</pre></dt>
|
||||
<dt><pre><span class="Keyword">proc</span> <a href="#buzz%2CT%2CT"><span class="Identifier">buzz</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">(</span><span class="Identifier">a</span><span class="Other">,</span> <span class="Identifier">b</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">deprecated</span><span class="Other">:</span> <span class="StringLit">"since v0.20"</span></span>.}</pre></dt>
|
||||
<dd>
|
||||
<div class="deprecation-message">
|
||||
<b>Deprecated:</b> since v0.20
|
||||
|
||||
@@ -6,6 +6,7 @@ C_D testproject.html#C_D testproject: C_D
|
||||
bar testproject.html#bar,T,T testproject: bar[T](a, b: T): T
|
||||
baz testproject.html#baz,T,T testproject: baz[T](a, b: T): T
|
||||
buzz testproject.html#buzz,T,T testproject: buzz[T](a, b: T): T
|
||||
FooBuzz testproject.html#FooBuzz testproject: FooBuzz
|
||||
aVariable testproject.html#aVariable testproject: aVariable
|
||||
A testproject.html#A testproject: A
|
||||
B testproject.html#B testproject: B
|
||||
|
||||
@@ -179,6 +179,10 @@ window.addEventListener('DOMContentLoaded', main);
|
||||
<li><a class="reference external"
|
||||
data-doc-search-tag="testproject: foo(a, b: SomeType)" href="testproject.html#foo.t%2CSomeType%2CSomeType">testproject: foo(a, b: SomeType)</a></li>
|
||||
</ul></dd>
|
||||
<dt><a name="FooBuzz" href="#FooBuzz"><span>FooBuzz:</span></a></dt><dd><ul class="simple">
|
||||
<li><a class="reference external"
|
||||
data-doc-search-tag="testproject: FooBuzz" href="testproject.html#FooBuzz">testproject: FooBuzz</a></li>
|
||||
</ul></dd>
|
||||
<dt><a name="fromUtils1" href="#fromUtils1"><span>fromUtils1:</span></a></dt><dd><ul class="simple">
|
||||
<li><a class="reference external"
|
||||
data-doc-search-tag="testproject: fromUtils1(): int" href="testproject.html#fromUtils1.i">testproject: fromUtils1(): int</a></li>
|
||||
|
||||
@@ -39,6 +39,9 @@ proc buzz*[T](a, b: T): T {.deprecated: "since v0.20".} =
|
||||
## This is deprecated with a message.
|
||||
result = a + b
|
||||
|
||||
type
|
||||
FooBuzz* {.deprecated: "FooBuzz msg".} = int
|
||||
|
||||
import std/macros
|
||||
|
||||
var aVariable*: array[1, int]
|
||||
|
||||
Reference in New Issue
Block a user