Skip to content

Commit

Permalink
julefmt: fix stmt spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Mar 28, 2024
1 parent 7d2361f commit 23a9e69
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ impl TypeFormatter {
fn write(self, s: str) {
self.fmt.buf += s
}

fn generics(self, mut g: []&ast::TypeDecl) {
if g.len == 0 {
ret
Expand Down Expand Up @@ -1265,28 +1266,34 @@ impl ScopeFormatter {
}
let mut i = 0
self.fmt.row = scope.stmts[0].token.row
let mut old = i
let mut z = i
for i < scope.stmts.len; i++ {
let mut stmt = scope.stmts[i]
if i > 0 {
self.write("\n")
}
z = self.fmt.row
self.fmt.add_global_padding_for_comment(stmt.token.row)
self.fmt.row = self.fmt.write_comments_except(stmt.token.row)
if stmt.token.row - self.fmt.row == 0 {
self.fmt.row = z
}
if stmt.token.row - self.fmt.row > 1 {
self.write("\n\n")
} else if i > 0 {
self.write("\n")
}
old = i
z = i
self.fmt.row = stmt.token.row
match type stmt.data {
| &ast::TypeAliasDecl:
self.fmt.group_decls[&ast::TypeAliasDecl, ast::Node](scope.stmts, i)
| &ast::VarDecl:
self.fmt.group_decls[&ast::VarDecl, ast::Node](scope.stmts, i)
|:
self.fmt.write_comments_except(self.fmt.row)
self.write(self.fmt.indent)
self.format_stmt(stmt.data)
self.fmt.pop_row_comments(self.fmt.row)
}
if old != i {
if z != i {
i--
self.fmt.buf = self.fmt.buf[:self.fmt.buf.len - 1]
}
Expand Down Expand Up @@ -1739,6 +1746,7 @@ impl ExprFormatter {
if expr.range {
self.write(")")
}
self.fmt.row = expr.end.row
}
}

Expand Down

0 comments on commit 23a9e69

Please sign in to comment.