diff options
| author | Bradley Lewis <22850972+BradLewis@users.noreply.github.com> | 2025-09-07 09:56:39 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-09-07 09:56:39 -0400 |
| commit | eb07da8a11477a08b5596b2537e3aaa656188f73 (patch) | |
| tree | 0b206c3bc99e96446fa09bd00a6b6683464f2507 /src | |
| parent | b0074c3a0df4f6ccf145b8348b172a16fb13553a (diff) | |
| parent | cad912bac0e9ff3ca6b4d23629b8490f9548d4b5 (diff) | |
Merge pull request #976 from BradLewis/fix/global-scope-decl-with-semicolon
Fix issue with the formatter stripping semicolons with globally scoped declarations
Diffstat (limited to 'src')
| -rw-r--r-- | src/odin/printer/printer.odin | 7 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin index aa3a771..227f909 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -232,8 +232,12 @@ print_file :: proc(p: ^Printer, file: ^ast.File) -> string { // Keep track of the first import in a row, to sort them later. import_group_start: Maybe(int) + prev_decl: ^ast.Stmt for decl, i in file.decls { decl := cast(^ast.Decl)decl + defer { + prev_decl = decl + } if imp, is_import := decl.derived.(^ast.Import_Decl); p.config.sort_imports && is_import { // First import in this group. @@ -257,6 +261,9 @@ print_file :: proc(p: ^Printer, file: ^ast.File) -> string { import_group_start = nil } + if prev_decl != nil && prev_decl.end.line == decl.pos.line && decl.pos.line not_in p.disabled_lines { + p.document = cons(p.document, break_with("; ")) + } p.document = cons(p.document, visit_decl(p, decl)) } } diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 2eef327..96890f3 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -2016,7 +2016,7 @@ visit_block_stmts :: proc(p: ^Printer, stmts: []^ast.Stmt) -> ^Document { for stmt, i in stmts { last_index := max(0, i - 1) if stmts[last_index].end.line == stmt.pos.line && i != 0 && stmt.pos.line not_in p.disabled_lines { - document = cons(document, break_with(";")) + document = group(cons(document, break_with("; "))) } if p.force_statement_fit { |