summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-09-07 03:23:33 +0800
committerGitHub <noreply@github.com>2022-09-06 21:23:33 +0200
commit557d79e7a2303f439d297655e3feb7219ef98fc6 (patch)
treeeb0b54b2d3fdf4854bcb973ed45d6aff2ce03c9e /compiler
parent5ebd1248dfe517fd932c401f71d1e5aeb023b0e4 (diff)
downloadNim-557d79e7a2303f439d297655e3feb7219ef98fc6.tar.gz
fixes #9462; jsondoc --index can generate a theindex.json (#20205)
Diffstat (limited to 'compiler')
-rw-r--r--compiler/docgen.nim16
-rw-r--r--compiler/main.nim6
2 files changed, 21 insertions, 1 deletions
diff --git a/compiler/docgen.nim b/compiler/docgen.nim
index a93dc01cf..bd973b211 100644
--- a/compiler/docgen.nim
+++ b/compiler/docgen.nim
@@ -1124,6 +1124,8 @@ proc genJsonItem(d: PDoc, n, nameNode: PNode, k: TSymKind): JsonItem =
         for kind in genericParam.sym.typ.sons:
           param["types"].add %($kind)
         result.json["signature"]["genericParams"].add param
+  if optGenIndex in d.conf.globalOptions:
+    genItem(d, n, nameNode, k, kForceExport)
 
 proc setDoctype(d: PDoc, n: PNode) =
   ## Processes `{.doctype.}` pragma changing Markdown/RST parsing options.
@@ -1782,3 +1784,17 @@ proc commandBuildIndex*(conf: ConfigRef, dir: string, outFile = RelativeFile"")
     writeFile(filename, code)
   except:
     rawMessage(conf, errCannotOpenFile, filename.string)
+
+proc commandBuildIndexJson*(conf: ConfigRef, dir: string, outFile = RelativeFile"") =
+  var (modules, symbols, docs) = readIndexDir(dir)
+  let documents = toSeq(keys(Table[IndexEntry, seq[IndexEntry]](docs)))
+  let body = %*({"documents": documents, "modules": modules, "symbols": symbols})
+
+  var outFile = outFile
+  if outFile.isEmpty: outFile = theindexFname.RelativeFile.changeFileExt("")
+  let filename = getOutFile(conf, outFile, JsonExt)
+
+  try:
+    writeFile(filename, $body)
+  except:
+    rawMessage(conf, errCannotOpenFile, filename.string)
diff --git a/compiler/main.nim b/compiler/main.nim
index 0354bec9c..171521c7a 100644
--- a/compiler/main.nim
+++ b/compiler/main.nim
@@ -325,7 +325,11 @@ proc mainCommand*(graph: ModuleGraph) =
       else:
         docLikeCmd commandDoc2(graph, TexExt)
   of cmdJsondoc0: docLikeCmd commandJson(cache, conf)
-  of cmdJsondoc: docLikeCmd commandDoc2(graph, JsonExt)
+  of cmdJsondoc:
+    docLikeCmd():
+      commandDoc2(graph, JsonExt)
+      if optGenIndex in conf.globalOptions and optWholeProject in conf.globalOptions:
+        commandBuildIndexJson(conf, $conf.outDir)
   of cmdCtags: docLikeCmd commandTags(cache, conf)
   of cmdBuildindex: docLikeCmd commandBuildIndex(conf, $conf.projectFull, conf.outFile)
   of cmdGendepend: commandGenDepend(graph)