Skip to content

Commit

Permalink
julefmt: improve brace lit formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Mar 24, 2024
1 parent d6e9b48 commit 21d92e9
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -1196,14 +1196,31 @@ impl ExprFormatter {
}

fn brace_lit(self, mut lit: &ast::BraceLit) {
self.write("{\n")
self.write("{")
self.fmt.add_indent()
for (_, mut expr) in lit.exprs {
self.write(self.fmt.indent)
let mut row = lit.token.row
let mut lined = false
for (i, mut expr) in lit.exprs {
if row != expr.token.row {
lined = true
self.write("\n")
self.write(self.fmt.indent)
} else if i > 0 {
self.write(" ")
}
self.format(expr)
self.write(",\n")
if lined || lit.exprs.len - i > 1 {
self.write(",")
}
row = expr.token.row
}
self.fmt.done_indent()
if self.fmt.buf[self.fmt.buf.len - 1] == '\n' {
self.write(self.fmt.indent)
} else if lined {
self.write("\n")
self.write(self.fmt.indent)
}
self.write("}")
}

Expand Down

0 comments on commit 21d92e9

Please sign in to comment.