From 3597824c000f375ae98cf22ed343d09dbb58204b Mon Sep 17 00:00:00 2001 From: Miran Date: Tue, 24 Nov 2020 14:26:52 +0100 Subject: [PATCH] fix export links in the documentation (#16114) [backport:1.4] * fix export links in the documentation * fix `len` problem (cherry picked from commit 9a86198ed5c27c11bf005588bd4e70927d30230e) --- compiler/docgen.nim | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 5104ad0707..94d65ba51e 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -717,7 +717,7 @@ proc complexName(k: TSymKind, n: PNode, baseName: string): string = of skTemplate: result.add(".t") of skConverter: result.add(".c") else: discard - if n.len > paramsPos and n[paramsPos].kind == nkFormalParams: + if n.safeLen > paramsPos and n[paramsPos].kind == nkFormalParams: let params = renderParamTypes(n[paramsPos]) if params.len > 0: result.add(defaultParamSeparator) @@ -966,13 +966,17 @@ proc exportSym(d: PDoc; s: PSym) = elif s.kind != skModule and s.owner != nil: let module = originatingModule(s) if belongsToPackage(d.conf, module): - let external = externalDep(d, module) + let + complexSymbol = complexName(s.kind, s.ast, s.name.s) + symbolOrIdRope = rope(d.newUniquePlainSymbol(complexSymbol)) + external = externalDep(d, module) if d.section[k] != nil: d.section[k].add(", ") # XXX proper anchor generation here dispA(d.conf, d.section[k], - "$1", + "$1", "$1", [rope esc(d.target, s.name.s), - rope changeFileExt(external, "html")]) + rope changeFileExt(external, "html"), + symbolOrIdRope]) proc documentNewEffect(cache: IdentCache; n: PNode): PNode = let s = n[namePos].sym @@ -1075,7 +1079,7 @@ proc generateDoc*(d: PDoc, n, orig: PNode, docFlags: DocFlags = kDefault) = if it.kind == nkSym: if d.module != nil and d.module == it.sym.owner: generateDoc(d, it.sym.ast, orig, kForceExport) - else: + elif it.sym.ast != nil: exportSym(d, it.sym) of nkExportExceptStmt: discard "transformed into nkExportStmt by semExportExcept" of nkFromStmt, nkImportExceptStmt: traceDeps(d, n[0])