Fixes #9364 and add moduleDescription to jsondoc (#9396)

This fixes `jsondoc0` so that it has comments in the output as described
by the documentation. It also fixes `jsondoc`/`jsondoc2` as it stored
it's output in a file with an html extension. Along with this it also
adds a new field `moduleDescription` to `jsondoc`/`jsondoc2` which
contains the module description.
This commit is contained in:
PMunch 2018-10-17 00:34:47 +02:00 • committed by Andreas Rumpf
commit db95fad6fa
4 changed files with 28 additions and 12 deletions

View file

@ -787,13 +787,13 @@ proc generateDoc*(d: PDoc, n, orig: PNode) =
proc add(d: PDoc; j: JsonNode) =
if j != nil: d.jArray.add j
proc generateJson*(d: PDoc, n: PNode) =
proc generateJson*(d: PDoc, n: PNode, includeComments: bool = true) =
case n.kind
of nkCommentStmt:
if startsWith(n.comment, "##"):
let stripped = n.comment.substr(2).strip
d.add %{ "comment": %stripped, "line": %n.info.line.int,
"col": %n.info.col }
if includeComments:
d.add %*{"comment": genComment(d, n)}
else:
add(d.modDesc, genComment(d, n))
of nkProcDef:
when useEffectSystem: documentRaises(d.cache, n)
d.add genJsonItem(d, n, n.sons[namePos], skProc)
@ -821,11 +821,11 @@ proc generateJson*(d: PDoc, n: PNode) =
succ(skType, ord(n.kind)-ord(nkTypeSection)))
of nkStmtList:
for i in countup(0, sonsLen(n) - 1):
generateJson(d, n.sons[i])
generateJson(d, n.sons[i], includeComments)
of nkWhenStmt:
# generate documentation for the first branch only:
if not checkForFalse(n.sons[0].sons[0]):
generateJson(d, lastSon(n.sons[0]))
generateJson(d, lastSon(n.sons[0]), includeComments)
else: discard
proc genTagsItem(d: PDoc, n, nameNode: PNode, k: TSymKind): string =
@ -951,8 +951,12 @@ proc writeOutput*(d: PDoc, useWarning = false) =
outfile.string)
proc writeOutputJson*(d: PDoc, useWarning = false) =
var modDesc: string
for desc in d.modDesc:
modDesc &= desc
let content = %*{"orig": d.filename,
"nimble": getPackageName(d.conf, d.filename),
"moduleDescription": modDesc,
"entries": d.jArray}
if optStdout in d.conf.globalOptions:
write(stdout, $content)
@ -962,7 +966,9 @@ proc writeOutputJson*(d: PDoc, useWarning = false) =
write(f, $content)
close(f)
else:
discard "fixme: error report"
localError(d.conf, newLineInfo(d.conf, AbsoluteFile d.filename, -1, -1),
warnUser, "unable to open file \"" & d.destFile.string &
"\" for writing")
proc commandDoc*(cache: IdentCache, conf: ConfigRef) =
var ast = parseFile(conf.projectMainIdx, cache, conf)