diff options
author | Jake Leahy <jake@leahy.dev> | 2023-07-21 03:56:04 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-20 19:56:04 +0200 |
commit | 3f9e16594fb26b78f812094a86d5e269093d8034 (patch) | |
tree | 92e81c7b2865d4009e5e0d97186241b41f4cceec | |
parent | c1a82aa5c5ab68dfc2ab6f09779d9ab9bbf3758f (diff) | |
download | Nim-3f9e16594fb26b78f812094a86d5e269093d8034.tar.gz |
fix `jsondoc` not getting `showNonExports` flag (#22267)
Pass the config down so we can check if the `--showNonExports` flag is used
-rw-r--r-- | compiler/docgen.nim | 17 | ||||
-rw-r--r-- | compiler/docgen2.nim | 2 |
2 files changed, 11 insertions, 8 deletions
diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 958d804b3..829d86dfd 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -1145,13 +1145,16 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags, nonEx if k == skType and nameNode.kind == nkSym: d.types.strTableAdd nameNode.sym -proc genJsonItem(d: PDoc, n, nameNode: PNode, k: TSymKind): JsonItem = +proc genJsonItem(d: PDoc, n, nameNode: PNode, k: TSymKind, nonExports = false): JsonItem = if not isVisible(d, nameNode): return var name = getNameEsc(d, nameNode) comm = genRecComment(d, n) r: TSrcGen - initTokRender(r, n, {renderNoBody, renderNoComments, renderDocComments, renderExpandUsing}) + renderFlags = {renderNoBody, renderNoComments, renderDocComments, renderExpandUsing} + if nonExports: + renderFlags.incl renderNonExportedFields + initTokRender(r, n, renderFlags) result.json = %{ "name": %name, "type": %($k), "line": %n.info.line.int, "col": %n.info.col} if comm != nil: @@ -1536,7 +1539,7 @@ proc finishGenerateDoc*(d: var PDoc) = proc add(d: PDoc; j: JsonItem) = if j.json != nil or j.rst != nil: d.jEntriesPre.add j -proc generateJson*(d: PDoc, n: PNode, includeComments: bool = true) = +proc generateJson*(d: PDoc, n: PNode, config: ConfigRef, includeComments: bool = true) = case n.kind of nkPragma: let doctypeNode = findPragma(n, wDoctype) @@ -1568,14 +1571,14 @@ proc generateJson*(d: PDoc, n: PNode, includeComments: bool = true) = if n[i].kind != nkCommentStmt: # order is always 'type var let const': d.add genJsonItem(d, n[i], n[i][0], - succ(skType, ord(n.kind)-ord(nkTypeSection))) + succ(skType, ord(n.kind)-ord(nkTypeSection)), optShowNonExportedFields in config.globalOptions) of nkStmtList: for i in 0..<n.len: - generateJson(d, n[i], includeComments) + generateJson(d, n[i], config, includeComments) of nkWhenStmt: # generate documentation for the first branch only: if not checkForFalse(n[0][0]): - generateJson(d, lastSon(n[0]), includeComments) + generateJson(d, lastSon(n[0]), config, includeComments) else: discard proc genTagsItem(d: PDoc, n, nameNode: PNode, k: TSymKind): string = @@ -1852,7 +1855,7 @@ proc commandJson*(cache: IdentCache, conf: ConfigRef) = status: int; content: string) {.gcsafe.} = localError(conf, newLineInfo(conf, AbsoluteFile d.filename, -1, -1), warnUser, "the ':test:' attribute is not supported by this backend") - generateJson(d, ast) + generateJson(d, ast, conf) finishGenerateDoc(d) let json = d.jEntriesFinal let content = pretty(json) diff --git a/compiler/docgen2.nim b/compiler/docgen2.nim index 0941be78a..907603412 100644 --- a/compiler/docgen2.nim +++ b/compiler/docgen2.nim @@ -56,7 +56,7 @@ proc processNodeJson*(c: PPassContext, n: PNode): PNode = result = n var g = PGen(c) if shouldProcess(g): - generateJson(g.doc, n, false) + generateJson(g.doc, n, g.config, false) template myOpenImpl(ext: untyped) {.dirty.} = var g: PGen |