Skip to content

Commit

Permalink
julefmt: fix handling of inlined blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Sep 22, 2024
1 parent b1afd32 commit 0134125
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -1547,7 +1547,14 @@ impl scopeFormatter {
self.fmt.buf.Write(self.fmt.indent)
}
self.formatStmt(stmt.Data)
self.fmt.popRowComments(self.fmt.row)
if !inline {
self.fmt.popRowComments(self.fmt.row)
} else {
self.fmt.popRowCommentsByF(self.fmt.row, scope.End.Column, fn(c: &comment) {
self.write(" ")
self.fmt.writeComment(c)
})
}
}
if z != i {
i--
Expand Down Expand Up @@ -1577,11 +1584,18 @@ impl scopeFormatter {
n := self.fmt.buf.Len()
comment := false
mut commentPtr := unsafe { (&bool)(&comment) }
self.fmt.popRowCommentsByF(self.fmt.row, -1, fn(c: &comment) {
self.write(" ")
self.fmt.writeComment(c)
*commentPtr = true
})
if len(scope.Stmts) > 0 {
self.fmt.popRowCommentsByF(self.fmt.row, scope.Stmts[0].Token.Column, fn(c: &comment) {
if c.txt[:2] == "//" {
self.write("\n")
self.fmt.buf.Write(self.fmt.indent)
*commentPtr = true
} else if !*commentPtr {
self.write(" ")
}
self.fmt.writeComment(c)
})
}
inline := (len(scope.Stmts) == 0 && !*commentPtr) ||
(len(scope.Stmts) == 1 &&
self.fmt.row == scope.End.Row &&
Expand Down Expand Up @@ -1609,6 +1623,7 @@ impl scopeFormatter {
}
self.write("}")
self.fmt.popRowComments(scope.End.Row)
self.fmt.row = scope.End.Row
}
}

Expand Down

0 comments on commit 0134125

Please sign in to comment.