nim doc now correctly renders deprecated pragmas for routines and types (#18515)
This commit is contained in:
parent
220b55c5d7
commit
488e9c2991
7 changed files with 59 additions and 17 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue