diff options
| author | Lucy <lucyperopero@gmail.com> | 2025-12-21 22:26:10 -0300 |
|---|---|---|
| committer | Lucy <lucyperopero@gmail.com> | 2025-12-21 22:26:10 -0300 |
| commit | 54d41706bff77584fafb6342d1af4748b3a40a11 (patch) | |
| tree | bf05eeba51a7aaa10ff56afcb3bacfb8af78ce6b | |
| parent | 93e39dcad2ad4aa5c07a0d2ff822b76d5f0e4ac5 (diff) | |
Add option to align struct value assignment
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | misc/odinfmt.schema.json | 5 | ||||
| -rw-r--r-- | src/odin/printer/printer.odin | 4 | ||||
| -rw-r--r-- | src/odin/printer/visit.odin | 2 |
4 files changed, 11 insertions, 2 deletions
@@ -160,6 +160,8 @@ Options: - `align_struct_fields`: Align the types of struct fields so they all start at the same column. +- `align_struct_values`: Align the values of struct fields when assigning a struct value to a variable so they all start at the same column. + ## Features Support Language server features: diff --git a/misc/odinfmt.schema.json b/misc/odinfmt.schema.json index a55872d..f30c999 100644 --- a/misc/odinfmt.schema.json +++ b/misc/odinfmt.schema.json @@ -75,6 +75,11 @@ "type": "boolean", "default": true, "description": "Align the types of struct fields so they all start at the same column" + }, + "align_struct_values": { + "type": "boolean", + "default": true, + "description": "Align the values of struct fields when assigning a struct value to a variable so they all start at the same column" } }, "required": [] diff --git a/src/odin/printer/printer.odin b/src/odin/printer/printer.odin index 698abb4..48897b8 100644 --- a/src/odin/printer/printer.odin +++ b/src/odin/printer/printer.odin @@ -55,6 +55,7 @@ Config :: struct { 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, + align_struct_values: bool, } Brace_Style :: enum { @@ -91,7 +92,6 @@ Line_Suffix_Option :: enum { Indent, } - when ODIN_OS == .Windows { default_style := Config { spaces = 4, @@ -106,6 +106,7 @@ when ODIN_OS == .Windows { sort_imports = true, spaces_around_colons = false, align_struct_fields = true, + align_struct_values = true, } } else { default_style := Config { @@ -121,6 +122,7 @@ when ODIN_OS == .Windows { sort_imports = true, spaces_around_colons = false, align_struct_fields = true, + align_struct_values = true, } } diff --git a/src/odin/printer/visit.odin b/src/odin/printer/visit.odin index 99af62e..40d3f83 100644 --- a/src/odin/printer/visit.odin +++ b/src/odin/printer/visit.odin @@ -798,7 +798,7 @@ visit_comp_lit_exprs :: proc(p: ^Printer, comp_lit: ast.Comp_Lit, options := Lis alignment := get_possible_comp_lit_alignment(comp_lit.elems) if value, ok := expr.derived.(^ast.Field_Value); ok && alignment > 0 { align := empty() - if should_align_comp_lit(p, comp_lit) { + if should_align_comp_lit(p, comp_lit) && p.config.align_struct_values { align = repeat_space(alignment - get_node_length(value.field)) } document = cons( |