From 5bc6bb0750dff12ba042669bc5a5be96406e4579 Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Wed, 18 Feb 2026 15:16:16 +0100 Subject: [PATCH] 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. --- src/formatter.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/formatter.lua b/src/formatter.lua index 00cdf01..dfd68ed 100644 --- a/src/formatter.lua +++ b/src/formatter.lua @@ -285,7 +285,11 @@ function M.format_document(content, options) if_base_level = nil end 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 formatted_line = formatted_line .. ";" end