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:
+16
-5
@@ -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,15 +339,21 @@ 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
|
||||
-- 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)
|
||||
goto continue
|
||||
|
||||
Reference in New Issue
Block a user