diff --git a/src/format.jule b/src/format.jule index 41eb0fd..0d7f50f 100644 --- a/src/format.jule +++ b/src/format.jule @@ -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() @@ -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 { @@ -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(",") } @@ -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("!")