From 15f11a3416edd013c3cbfc3608313457c7277043 Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Mon, 23 Feb 2026 13:54:39 +0100 Subject: [PATCH] fix: reset in_assignment after multiline assignment ends - Fix formatter to properly detect when multiline assignment ends - Add check for line ending with := and ; before checking continuation - Fixes issue where subsequent lines were incorrectly indented --- src/formatter.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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