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
This commit is contained in:
2026-02-23 14:06:32 +01:00
parent 15f11a3416
commit d69e41adb1
+18 -7
View File
@@ -134,7 +134,12 @@ function M.format_document(content, options)
local function is_assignment_continuation(trimmed) local function is_assignment_continuation(trimmed)
if not trimmed then return false end 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 if first_word and CONTINUATION_OPERATORS[first_word:upper()] then
return true return true
end end
@@ -334,14 +339,20 @@ function M.format_document(content, options)
-- Check if continuing assignment -- Check if continuing assignment
-- Continuation if: in assignment AND (starts with operator OR doesn't start new statement) -- 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 if in_assignment and not ends_assignment then
local starts_with_operator = is_assignment_continuation(trimmed) local starts_with_operator = is_assignment_continuation(trimmed)
local is_new_statement = trimmed:match("^%w+") and ( -- New statement if: starts with keyword OR contains := (new assignment) OR starts with block ender
trimmed:match(":=") or local first_word = trimmed:match("^([%w_]+)")
BLOCKS[trimmed:match("^([%w_]+)")] or local starts_block_ender = first_word and (
SAME_LEVEL[trimmed:match("^([%w_]+)")] or trimmed:match("^END_") or
VAR_KEYWORDS[trimmed:match("^([%w_]+)")] 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 if starts_with_operator or not is_new_statement then
table.insert(formatted_lines, assignment_continuation_indent .. trimmed) table.insert(formatted_lines, assignment_continuation_indent .. trimmed)