Skip to content

Commit

Permalink
julefmt: minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mertcandav committed Mar 31, 2024
1 parent da243a1 commit 2a3dbb5
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/format.jule
Original file line number Diff line number Diff line change
Expand Up @@ -816,35 +816,43 @@ impl Formatter {
self.pop_row_comments(d.end.row)
}

fn group_node[T](&self, &node: ast::Node) {
let mut row = node.token.row
match type T {
| &ast::TypeAliasDecl:
break
|:
let data = (T)(node.data)
if data.directives.len > 0 {
row = data.directives[0].tag.row
}
}
if row-self.write_comments_except(row) > 1 {
self.write("\n")
}
self.group_decls[T, ast::Node](self.f.nodes, self.i)
}

fn node(&self, mut &node: ast::Node) {
match type node.data {
| &ast::TypeAliasDecl:
if node.token.row-self.write_comments_except(node.token.row) > 1 {
self.write("\n")
}
self.group_decls[&ast::TypeAliasDecl, ast::Node](self.f.nodes, self.i)
self.group_node[&ast::TypeAliasDecl](node)
ret
| &ast::VarDecl:
if node.token.row-self.write_comments_except(node.token.row) > 1 {
self.write("\n")
}
self.group_decls[&ast::VarDecl, ast::Node](self.f.nodes, self.i)
self.group_node[&ast::VarDecl](node)
ret
| &ast::FnDecl:
if node.token.row-self.write_comments_except(node.token.row) > 1 {
self.write("\n")
}
self.group_decls[&ast::FnDecl, ast::Node](self.f.nodes, self.i)
self.group_node[&ast::FnDecl](node)
ret
| &ast::StructDecl:
self.struct_decl((&ast::StructDecl)(node.data))
}
if node.token.row-self.write_comments(node.token.row) > 1 {
self.write("\n")
}
match type node.data {
| &ast::EnumDecl:
self.enum_decl((&ast::EnumDecl)(node.data))
| &ast::StructDecl:
self.struct_decl((&ast::StructDecl)(node.data))
| &ast::TraitDecl:
self.trait_decl((&ast::TraitDecl)(node.data))
| &ast::Impl:
Expand Down Expand Up @@ -1848,7 +1856,7 @@ impl ExprFormatter {
}

struct BinaryFormatter {
mut ef: &ExprFormatter
mut ef: &ExprFormatter
mut zip: bool
mut strict: bool
mut op: bool
Expand Down

0 comments on commit 2a3dbb5

Please sign in to comment.