From f8d538f4ad35c2ff6f8403d8fb3a66e47dc98d5d Mon Sep 17 00:00:00 2001 From: metagn Date: Sun, 24 Dec 2023 17:22:10 +0300 Subject: [PATCH] fix spurious indent and newlines in rendering of nkRecList (#23121) Rendering of `nkRecList` produces an indent and adds a new line at the end. However for things like case object `of`/`else` branches or `when` branches this is already done, so this produces 2 indents and an extra new line. Instead, just add an indent in the place where the indent that `nkRecList` produces is needed, for the rendering of the final node of `nkObjectTy`. There doesn't seem to be a need to add the newline. Before: ```nim case x*: bool of true: y*: int of false: nil ``` After: ```nim case x*: bool of true: y*: int of false: nil ``` (cherry picked from commit fc49c6e3ba5081593e4d9af7e04bfb84e97a39f5) --- compiler/renderer.nim | 5 ++--- lib/core/macros.nim | 3 +-- nimdoc/extlinks/project/expected/main.html | 3 +-- .../expected/subdir/subdir_b/utils.html | 3 +-- nimdoc/testproject/expected/testproject.html | 16 +++++----------- 5 files changed, 10 insertions(+), 20 deletions(-) diff --git a/compiler/renderer.nim b/compiler/renderer.nim index d60455a551..bb4e740c19 100644 --- a/compiler/renderer.nim +++ b/compiler/renderer.nim @@ -1526,17 +1526,16 @@ proc gsub(g: var TSrcGen, n: PNode, c: TContext, fromStmtList = false) = gsub(g, n[0]) gsub(g, n[1]) gcoms(g) + indentNL(g) gsub(g, n[2]) + dedent(g) else: put(g, tkObject, "object") of nkRecList: - indentNL(g) for i in 0..Types
-
A = object
-  
+
A = object
diff --git a/nimdoc/testproject/expected/subdir/subdir_b/utils.html b/nimdoc/testproject/expected/subdir/subdir_b/utils.html index cfdac53107..ccabe35a74 100644 --- a/nimdoc/testproject/expected/subdir/subdir_b/utils.html +++ b/nimdoc/testproject/expected/subdir/subdir_b/utils.html @@ -253,8 +253,7 @@ Ref. Types
-
G[T] = object
-  
+
G[T] = object
diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html index 78a730e598..ad848f3af5 100644 --- a/nimdoc/testproject/expected/testproject.html +++ b/nimdoc/testproject/expected/testproject.html @@ -59,8 +59,7 @@
  • AnotherObject
  • B
  • @@ -380,11 +379,8 @@
    AnotherObject = object
       case x*: bool
       of true:
    -      y*: proc (x: string)
    -
    -  of false:
    -    
    -  
    + y*: proc (x: string) + of false:
    @@ -423,8 +419,7 @@
    MyObject = object
       someString*: string        ## This is a string
    -  annotated* {.somePragma.}: string ## This is an annotated string
    -  
    + annotated* {.somePragma.}: string ## This is an annotated string
    @@ -444,8 +439,7 @@
    T19396 = object
    -  a*: int
    -  
    + a*: int