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
This commit is contained in:
+8
-2
@@ -329,9 +329,13 @@ function M.format_document(content, options)
|
|||||||
|
|
||||||
trimmed = collapse_attribute_block(trimmed)
|
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
|
-- 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)
|
||||||
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 starts_with_operator = is_assignment_continuation(trimmed)
|
||||||
local is_new_statement = trimmed:match("^%w+") and (
|
local is_new_statement = trimmed:match("^%w+") and (
|
||||||
trimmed:match(":=") or
|
trimmed:match(":=") or
|
||||||
@@ -518,7 +522,9 @@ function M.format_document(content, options)
|
|||||||
local var_trimmed = var_part:match("^(.-)%s*$")
|
local var_trimmed = var_part:match("^(.-)%s*$")
|
||||||
assignment_continuation_indent = base_indent .. string.rep(" ", #var_trimmed + 4)
|
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
|
in_assignment = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user