From d69e41adb15522f19f6fe8bc90d2c7e7af49d5ed Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Mon, 23 Feb 2026 14:06:32 +0100 Subject: [PATCH] fix: improve multiline assignment continuation detection - Detect continuation lines starting with # (SCL variable references) - Detect block enders (END_REGION, END_IF, etc.) as new statements - Fixes multiline assignments with #variable OR continuation pattern --- src/formatter.lua | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/formatter.lua b/src/formatter.lua index d646cee..0bf6c28 100644 --- a/src/formatter.lua +++ b/src/formatter.lua @@ -134,7 +134,12 @@ function M.format_document(content, options) local function is_assignment_continuation(trimmed) if not trimmed then return false end - local first_word = trimmed:match("^(%w+)") + local first_word + if trimmed:match("^#") then + first_word = trimmed:match("^#(%w+)") + else + first_word = trimmed:match("^(%w+)") + end if first_word and CONTINUATION_OPERATORS[first_word:upper()] then return true end @@ -334,14 +339,20 @@ function M.format_document(content, options) -- Check if continuing assignment -- Continuation if: in assignment AND (starts with operator OR doesn't start new statement) - -- BUT NOT if this line ends an assignment + -- BUT NOT if this line ends an assignment OR starts a new assignment (contains :=) OR starts with block ender 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 - BLOCKS[trimmed:match("^([%w_]+)")] or - SAME_LEVEL[trimmed:match("^([%w_]+)")] or - VAR_KEYWORDS[trimmed:match("^([%w_]+)")] + -- New statement if: starts with keyword OR contains := (new assignment) OR starts with block ender + local first_word = trimmed:match("^([%w_]+)") + local starts_block_ender = first_word and ( + trimmed:match("^END_") or + BLOCKS[first_word] ~= nil + ) + local is_new_statement = trimmed:match(":=") or starts_block_ender or ( + trimmed:match("^%w+") and ( + SAME_LEVEL[trimmed:match("^([%w_]+)")] or + VAR_KEYWORDS[trimmed:match("^([%w_]+)")] + ) ) if starts_with_operator or not is_new_statement then table.insert(formatted_lines, assignment_continuation_indent .. trimmed)