Skip to content

Commit

Permalink
julefmt: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Apr 1, 2024
1 parent 9bb9d48 commit 84e4081
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -1392,15 +1392,21 @@ impl ScopeFormatter {
}
self.write("{")
let n = self.fmt.buf.len
let comment = false
let mut comment_ptr = unsafe { (&bool)(&comment) }
self.fmt.pop_row_comments_by_f(self.fmt.row, -1, fn(c: &Comment) {
self.write(" ")
self.fmt.write_comment(c)
*comment_ptr = true
})
let inline = scope.stmts.len == 1 &&
self.fmt.row == scope.end.row &&
scope.stmts[0].token.row == scope.end.row
let inline = (scope.stmts.len == 0 && !*comment_ptr) ||
(scope.stmts.len == 1 &&
self.fmt.row == scope.end.row &&
scope.stmts[0].token.row == scope.end.row)
if inline {
self.write(" ")
if scope.stmts.len > 0 {
self.write(" ")
}
} else {
self.write("\n")
self.fmt.add_indent()
Expand All @@ -1410,7 +1416,9 @@ impl ScopeFormatter {
self.fmt.done_indent()
}
if inline {
self.fmt.buf[self.fmt.buf.len - 1] = ' '
if scope.stmts.len > 0 {
self.fmt.buf[self.fmt.buf.len - 1] = ' '
}
} else if n == self.fmt.buf.len {
self.fmt.buf = self.fmt.buf[:n - 1]
} else {
Expand Down Expand Up @@ -1518,13 +1526,13 @@ impl ExprFormatter {
self.bf.binary(bin)
}

fn args(&self, mut &args: []&ast::Expr) {
if args.len == 0 {
fn args(&self, mut &f: &ast::FnCallExpr) {
if f.args.len == 0 {
ret
}
let mut row = args[0].token.row
let mut row = f.token.row
let mut indented = false
for (i, mut arg) in args {
for (i, mut arg) in f.args {
if i > 0 {
self.write(",")
}
Expand Down Expand Up @@ -1556,7 +1564,7 @@ impl ExprFormatter {
}
tf.generics(f.generics)
self.write("(")
self.args(f.args)
self.args(f)
self.write(")")
if f.ignored() {
self.write("!")
Expand Down

0 comments on commit 84e4081

Please sign in to comment.