aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLucy <lucyperopero@gmail.com>2025-12-21 05:25:19 -0300
committerLucy <lucyperopero@gmail.com>2025-12-21 05:25:19 -0300
commit55c3d1831d40eb6cd17990049c5487b9fef1a4a3 (patch)
tree9d36d93f83265a1dd5e263db045df570a5051ef2 /src
parent47f9c665dc12c3b702e2d2e8506f44367b344e24 (diff)
Add config flag to align struct fields
Diffstat (limited to 'src')
-rw-r--r--src/odin/printer/printer.odin3
-rw-r--r--src/odin/printer/visit.odin8
2 files changed, 7 insertions, 4 deletions
diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin
index 227f909..698abb4 100644
--- a/src/odin/printer/printer.odin
+++ b/src/odin/printer/printer.odin
@@ -54,6 +54,7 @@ Config :: struct {
inline_single_stmt_case: bool,
spaces_around_colons: bool, //Put spaces to the left of a colon as well as the right. `foo: bar` => `foo : bar`
space_single_line_blocks: bool,
+ align_struct_fields: bool,
}
Brace_Style :: enum {
@@ -104,6 +105,7 @@ when ODIN_OS == .Windows {
character_width = 100,
sort_imports = true,
spaces_around_colons = false,
+ align_struct_fields = true,
}
} else {
default_style := Config {
@@ -118,6 +120,7 @@ when ODIN_OS == .Windows {
character_width = 100,
sort_imports = true,
spaces_around_colons = false,
+ align_struct_fields = true,
}
}
diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin
index 6bd0800..6e3e852 100644
--- a/src/odin/printer/visit.odin
+++ b/src/odin/printer/visit.odin
@@ -2081,8 +2081,8 @@ visit_struct_field_list :: proc(p: ^Printer, list: ^ast.Field_List, options := L
}
name_options := List_Options{.Add_Comma}
-
- if (.Enforce_Newline in options) {
+
+ if (.Enforce_Newline in options) && p.config.align_struct_fields {
alignment := get_possible_field_alignment(list.list)
if alignment > 0 {
@@ -2096,10 +2096,10 @@ visit_struct_field_list :: proc(p: ^Printer, list: ^ast.Field_List, options := L
length += 9
}
}
- // align = repeat_space(alignment - length)
+ align = repeat_space(alignment - length)
}
document = cons(document, visit_exprs(p, field.names, name_options))
- } else {
+ } else if (.Enforce_Newline in options) {
document = cons_with_opl(document, visit_exprs(p, field.names, name_options))
}