From e39fa19cdb45c22eb691a752a833122cffe1c727 Mon Sep 17 00:00:00 2001 From: Lazar Bulovan Date: Tue, 24 Feb 2026 18:51:18 +0100 Subject: [PATCH] fix: prevent attribute block lines from being treated as assignments The formatter was incorrectly treating multi-line attribute blocks as assignments, causing AUTHOR/VERSION lines to get weird indentation. Lines like: { S7_Optimized_Access := 'TRUE' } VERSION : 0.1 Were being processed incorrectly because the attribute block line contains := but no semicolon, causing the formatter to treat the next line as a continuation. Fix by tracking in_attr_block state and skipping assignment detection for lines inside or exiting attribute blocks. --- src/formatter.lua | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/formatter.lua b/src/formatter.lua index 77438b0..7dfb4b6 100644 --- a/src/formatter.lua +++ b/src/formatter.lua @@ -359,6 +359,7 @@ function M.format_document(content, options) local assignment_continuation_indent = "" local in_condition = false local condition_indent = "" + local in_attr_block = false for line_num, line in ipairs(lines) do local trimmed = line:gsub("^%s+", ""):gsub("%s+$", "") @@ -377,6 +378,18 @@ function M.format_document(content, options) trimmed = collapse_attribute_block(trimmed) + -- Track if we're entering or exiting an attribute block + local has_open_brace = trimmed:find("{") + local has_close_brace = trimmed:find("}") + local exiting_attr_block = false + + if has_open_brace and not has_close_brace then + in_attr_block = true + elseif has_close_brace and not has_open_brace then + in_attr_block = false + exiting_attr_block = true + end + -- Check if this line ends an assignment (has := and ends with ;) local ends_assignment = trimmed:match(":=") and trimmed:match(";%s*$") @@ -602,7 +615,8 @@ function M.format_document(content, options) end -- Regular line - check for assignment start - if trimmed:match(":=") then + -- But not if its inside an attribute block, exiting one, or a single-line attribute block + if not in_attr_block and not exiting_attr_block and trimmed:match(":=") and not trimmed:match("^{.*}$") then local base_indent = get_indent() local assign_pos = trimmed:find(":=") if assign_pos then @@ -619,6 +633,11 @@ function M.format_document(content, options) else in_assignment = false end + + -- Also reset assignment state when in attribute block + if in_attr_block then + in_assignment = false + end local formatted = get_indent() .. trimmed if NEEDS_SEMICOLON[kw] and trimmed:sub(-1) ~= ";" then