diff options
| author | Laytan Laats <laytanlaats@hotmail.com> | 2024-08-31 00:45:56 +0200 |
|---|---|---|
| committer | Laytan Laats <laytanlaats@hotmail.com> | 2024-08-31 00:45:56 +0200 |
| commit | 8841c68bcc33ba9bca30ae3508e23bd49cf06ee5 (patch) | |
| tree | 73616100d1aa1ac855b355625ae2cb6cb72511f4 /src | |
| parent | bd60025df3b54c22a8bcb5745b98a30f88162ddd (diff) | |
fix formatting of `@(require)` imports
Diffstat (limited to 'src')
| -rw-r--r-- | src/odin/printer/printer.odin | 6 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 9 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin index 1c5f5b2..73a544e 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -273,6 +273,12 @@ print_sorted_imports :: proc(p: ^Printer, decls: []^ast.Stmt) { decl.pos.line = start_line + i decl.end.line = start_line + i + imp := decl.derived.(^ast.Import_Decl) + for attr in imp.attributes { + attr.pos.line = start_line + i + attr.end.line = start_line + i + } + p.document = cons(p.document, visit_decl(p, cast(^ast.Decl)decl)) } } diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 02e2867..4c8902b 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -265,12 +265,13 @@ visit_decl :: proc(p: ^Printer, decl: ^ast.Decl, called_in_stmt := false) -> ^Do return document case ^Import_Decl: - document := move_line(p, decl.pos) - + document := empty() if len(v.attributes) > 0 { document = cons(document, visit_attributes(p, &v.attributes, v.pos)) } + document = cons(document, move_line(p, decl.pos)) + if v.name.text != "" { document = cons( document, @@ -820,8 +821,8 @@ visit_attributes :: proc(p: ^Printer, attributes: ^[dynamic]^ast.Attribute, pos: //Ensure static is not forced newline, but until if the width is full if len(attributes) == 1 && len(attributes[0].elems) == 1 { - if ident, ok := attributes[0].elems[0].derived.(^ast.Ident); ok && ident.name == "static" { - document = cons(document, text("@"), text("("), visit_expr(p, attributes[0].elems[0]), text(")")) + if ident, ok := attributes[0].elems[0].derived.(^ast.Ident); ok && (ident.name == "static" || ident.name == "require") { + document = cons(document, text("@"), text("("), visit_expr(p, attributes[0].elems[0]), text(")"), break_with_no_newline()) set_source_position(p, pos) return document } |