diff options
| author | Daniel Gavin <danielgavin5@hotmail.com> | 2022-07-21 01:28:56 +0200 |
|---|---|---|
| committer | Daniel Gavin <danielgavin5@hotmail.com> | 2022-07-21 01:28:56 +0200 |
| commit | 53d13ab19c1a0039f9c5a5645081aea63fe18aa3 (patch) | |
| tree | b1ce2d58be2ac2d76d998d7f6ba23ed27f2593ab | |
| parent | fa46573d263ae3202dd6820147968b4cfb43fa4b (diff) | |
odinfmt: Improve breaking of proc types with single return result
| -rw-r--r-- | src/odin/printer/visit.odin | 8 | ||||
| -rw-r--r-- | tools/odinfmt/tests/.snapshots/procedures.odin | 5 | ||||
| -rw-r--r-- | tools/odinfmt/tests/random/.snapshots/demo.odin | 7 | ||||
| -rw-r--r-- | tools/odinfmt/tests/random/.snapshots/document.odin | 13 |
4 files changed, 21 insertions, 12 deletions
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index c3b6bb4..4799f26 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -1585,7 +1585,7 @@ visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type, contains_body: bo } document = cons(document, nest(cons(break_with(""), visit_signature_list(p, proc_type.params, contains_body, false)))) - document = group(cons(document, cons(break_with(""), text(")")))) + document = cons(document, cons(break_with(""), text(")"))) if proc_type.results != nil && len(proc_type.results.list) > 0 { document = cons_with_nopl(document, text("-")) @@ -1608,9 +1608,9 @@ visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type, contains_body: bo if use_parens { document = cons_with_nopl(document, text("(")) document = cons(document, nest(cons(break_with(""), visit_signature_list(p, proc_type.results, contains_body, true)))) - document = group(cons(document, cons(break_with(""), text(")")))) + document = cons(document, cons(break_with(""), text(")"))) } else { - document = cons(document, group(nest(cons(break_with(" "), group(visit_signature_list(p, proc_type.results, contains_body, true)))))) + document = cons_with_nopl(document, nest(group(visit_signature_list(p, proc_type.results, contains_body, true)))) } } else if proc_type.diverging { document = cons_with_nopl(document, text("-")) @@ -1620,7 +1620,7 @@ visit_proc_type :: proc(p: ^Printer, proc_type: ast.Proc_Type, contains_body: bo document = cons_with_opl(document, visit_proc_tags(p, proc_type.tags)) - return document + return group(document) } diff --git a/tools/odinfmt/tests/.snapshots/procedures.odin b/tools/odinfmt/tests/.snapshots/procedures.odin index 50bf04d..9ef6ecd 100644 --- a/tools/odinfmt/tests/.snapshots/procedures.odin +++ b/tools/odinfmt/tests/.snapshots/procedures.odin @@ -1,8 +1,9 @@ package odinfmt_test -GetPhysicsBody :: proc(index: int) -> - ReallllllllllllllllllllllllllllllllllllllyThiccccccccccccccccccccccccPhysicsBody +GetPhysicsBody :: proc( + index: int +) -> ReallllllllllllllllllllllllllllllllllllllyThiccccccccccccccccccccccccPhysicsBody tracking_allocator_check_leaks :: proc( diff --git a/tools/odinfmt/tests/random/.snapshots/demo.odin b/tools/odinfmt/tests/random/.snapshots/demo.odin index 0347f05..3814f7a 100644 --- a/tools/odinfmt/tests/random/.snapshots/demo.odin +++ b/tools/odinfmt/tests/random/.snapshots/demo.odin @@ -1023,8 +1023,11 @@ parametric_polymorphism :: proc() { return table.slots[index].value, true } - find_index :: proc(table: ^Table($Key, $Value), key: Key, hash: u32) -> - int { + find_index :: proc( + table: ^Table($Key, $Value), + key: Key, + hash: u32, + ) -> int { if len(table.slots) <= 0 { return -1 } diff --git a/tools/odinfmt/tests/random/.snapshots/document.odin b/tools/odinfmt/tests/random/.snapshots/document.odin index 228d571..e309517 100644 --- a/tools/odinfmt/tests/random/.snapshots/document.odin +++ b/tools/odinfmt/tests/random/.snapshots/document.odin @@ -160,8 +160,10 @@ enforce_break :: proc( return document } -align :: proc(aligned_document: ^Document, allocator := context.allocator) -> - ^Document { +align :: proc( + aligned_document: ^Document, + allocator := context.allocator, +) -> ^Document { document := new(Document, allocator) document^ = Document_Align { document = aligned_document, @@ -211,8 +213,11 @@ group :: proc( return document } -cons :: proc(lhs: ^Document, rhs: ^Document, allocator := context.allocator) -> - ^Document { +cons :: proc( + lhs: ^Document, + rhs: ^Document, + allocator := context.allocator, +) -> ^Document { document := new(Document, allocator) document^ = Document_Cons { lhs = lhs, |