diff --git a/src/formatter.lua b/src/formatter.lua index 44ee0be..d646cee 100644 --- a/src/formatter.lua +++ b/src/formatter.lua @@ -329,9 +329,13 @@ function M.format_document(content, options) trimmed = collapse_attribute_block(trimmed) + -- Check if this line ends an assignment (has := and ends with ;) + local ends_assignment = trimmed:match(":=") and trimmed:match(";%s*$") + -- Check if continuing assignment -- Continuation if: in assignment AND (starts with operator OR doesn't start new statement) - if in_assignment then + -- BUT NOT if this line ends an assignment + if in_assignment and not ends_assignment then local starts_with_operator = is_assignment_continuation(trimmed) local is_new_statement = trimmed:match("^%w+") and ( trimmed:match(":=") or @@ -518,7 +522,9 @@ function M.format_document(content, options) local var_trimmed = var_part:match("^(.-)%s*$") assignment_continuation_indent = base_indent .. string.rep(" ", #var_trimmed + 4) - if not trimmed:match(";%s*$") then + if trimmed:match(";%s*$") then + in_assignment = false + else in_assignment = true end end