From 72b480f37bbba0b019f919979bcc8297c39e7980 Mon Sep 17 00:00:00 2001 From: metagn <10591326+metagn@users.noreply.github.com> Date: Tue, 19 Dec 2023 20:41:21 +0300 Subject: [PATCH] fix/adapt docgen --- compiler/docgen.nim | 16 ++++++---- nimdoc/extlinks/project/expected/main.html | 4 +-- .../project/expected/sub/submodule.html | 4 +-- .../expected/subdir/subdir_b/utils.html | 8 ++--- nimdoc/testproject/expected/testproject.html | 32 +++++++++---------- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index bf8bdde143a4..9fb201f73ea5 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -1086,6 +1086,9 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags, nonEx symbolOrIdEnc = encodeUrl(symbolOrId, usePlus = false) deprecationMsg = genDeprecationMsg(d, pragmaNode) rstLangSymbol = toLangSymbol(k, n, cleanPlainSymbol) + symNameNode = + if nameNode.kind == nkPostfix: nameNode[1] + else: nameNode # we generate anchors automatically for subsequent use in doc comments let lineinfo = rstast.TLineInfo( @@ -1122,18 +1125,19 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags, nonEx let external = d.destFile.AbsoluteFile.relativeTo(d.conf.outDir, '/').changeFileExt(HtmlExt).string var attype = "" - if k in routineKinds and nameNode.kind == nkSym: + if k in routineKinds and symNameNode.kind == nkSym: let att = attachToType(d, nameNode.sym) if att != nil: attype = esc(d.target, att.name.s) - elif k == skType and nameNode.kind == nkSym and nameNode.sym.typ.kind in {tyEnum, tyBool}: - let etyp = nameNode.sym.typ + elif k == skType and symNameNode.kind == nkSym and + symNameNode.sym.typ.kind in {tyEnum, tyBool}: + let etyp = symNameNode.sym.typ for e in etyp.n: if e.sym.kind != skEnumField: continue let plain = renderPlainSymbolName(e) let symbolOrId = d.newUniquePlainSymbol(plain) setIndexTerm(d[], ieNim, htmlFile = external, id = symbolOrId, - term = plain, linkTitle = nameNode.sym.name.s & '.' & plain, + term = plain, linkTitle = symNameNode.sym.name.s & '.' & plain, linkDesc = xmltree.escape(getPlainDocstring(e).docstringSummary), line = n.info.line.int) @@ -1154,8 +1158,8 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags, nonEx linkTitle = detailedName, linkDesc = xmltree.escape(plainDocstring.docstringSummary), line = n.info.line.int) - if k == skType and nameNode.kind == nkSym: - d.types.strTableAdd nameNode.sym + if k == skType and symNameNode.kind == nkSym: + d.types.strTableAdd symNameNode.sym proc genJsonItem(d: PDoc, n, nameNode: PNode, k: TSymKind, nonExports = false): JsonItem = if not isVisible(d, nameNode): return diff --git a/nimdoc/extlinks/project/expected/main.html b/nimdoc/extlinks/project/expected/main.html index 1a58ea2ac7b0..e1afdf15e660 100644 --- a/nimdoc/extlinks/project/expected/main.html +++ b/nimdoc/extlinks/project/expected/main.html @@ -55,7 +55,7 @@

nimdoc/extlinks/project/main

Types
@@ -95,7 +95,7 @@

Imports

Types

-
A = object
+  
A* = object
   
diff --git a/nimdoc/extlinks/project/expected/sub/submodule.html b/nimdoc/extlinks/project/expected/sub/submodule.html index 60887ae37ad3..4cacd6f212c7 100644 --- a/nimdoc/extlinks/project/expected/sub/submodule.html +++ b/nimdoc/extlinks/project/expected/sub/submodule.html @@ -51,7 +51,7 @@

nimdoc/extlinks/project/sub/submodule

Types
@@ -84,7 +84,7 @@

nimdoc/extlinks/project/sub/submodule

Types

-
submoduleInt = distinct int
+
submoduleInt* = distinct int
diff --git a/nimdoc/testproject/expected/subdir/subdir_b/utils.html b/nimdoc/testproject/expected/subdir/subdir_b/utils.html index ba9512d5a9d7..64fbe846e1e8 100644 --- a/nimdoc/testproject/expected/subdir/subdir_b/utils.html +++ b/nimdoc/testproject/expected/subdir/subdir_b/utils.html @@ -59,8 +59,8 @@

subdir/subdir_b/utils

Types @@ -253,7 +253,7 @@

Types

-
G[T] = object
+  
G*[T] = object
   
@@ -262,7 +262,7 @@

Types

-
SomeType = enum
+  
SomeType* = enum
   enumValueA, enumValueB, enumValueC
diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html index db49102f85aa..d4d9f0912115 100644 --- a/nimdoc/testproject/expected/testproject.html +++ b/nimdoc/testproject/expected/testproject.html @@ -54,27 +54,27 @@

testproject

Types @@ -368,7 +368,7 @@

Imports

Types

-
A {.inject.} = enum
+  
A* {.inject.} = enum
   aA
@@ -377,7 +377,7 @@

Types

-
AnotherObject = object
+  
AnotherObject* = object
   case x*: bool
   of true:
       y*: proc (x: string)
@@ -392,7 +392,7 @@ 

Types

-
B {.inject.} = enum
+  
B* {.inject.} = enum
   bB
@@ -401,7 +401,7 @@

Types

-
Foo = enum
+  
Foo* = enum
   enumValueA2
@@ -410,7 +410,7 @@

Types

-
FooBuzz {....deprecated: "FooBuzz msg".} = int
+
FooBuzz* {....deprecated: "FooBuzz msg".} = int
Deprecated: FooBuzz msg @@ -421,7 +421,7 @@

Types

-
MyObject = object
+  
MyObject* = object
   someString*: string        ## This is a string
   annotated* {.somePragma.}: string ## This is an annotated string
   
@@ -432,7 +432,7 @@

Types

-
Shapes = enum
+  
Shapes* = enum
   Circle,                   ## A circle
   Triangle,                 ## A three-sided shape
   Rectangle                  ## A four-sided shape
@@ -443,7 +443,7 @@

Types

-
T19396 = object
+  
T19396* = object
   a*: int