fix(formatter): Keep END_IF at same indent level as content

Per TIA Portal standard, END_IF stays at the same indent level as the
code inside the IF block, rather than decreasing. This matches the
reference file Em101Sequence.scl where nested END_IF statements are
properly aligned.
This commit is contained in:
2026-02-18 15:16:16 +01:00
parent 5b5d9c46f6
commit 5bc6bb0750
+5 -1
View File
@@ -285,7 +285,11 @@ function M.format_document(content, options)
if_base_level = nil if_base_level = nil
end end
in_fb_call = false -- Reset FB call state in_fb_call = false -- Reset FB call state
indent_level = math.max(0, indent_level - 1) -- Don't decrease indent for END_IF - it stays at same level as content (per TIA Portal)
-- Only decrease for other enders like END_REGION, END_CASE, END_FOR, etc.
if kw ~= "END_IF" then
indent_level = math.max(0, indent_level - 1)
end
if needs_semicolon(trimmed) then if needs_semicolon(trimmed) then
formatted_line = formatted_line .. ";" formatted_line = formatted_line .. ";"
end end