diff --git a/src/formatter.lua b/src/formatter.lua index 69f2473..00cdf01 100644 --- a/src/formatter.lua +++ b/src/formatter.lua @@ -72,6 +72,7 @@ function M.format_document(content, options) local in_fb_call = false local fb_call_indent = 0 local fb_name_length = 0 + local fb_call_first_line = false local function get_indent() return string.rep(indent_char, indent_level * indent_size) @@ -204,6 +205,7 @@ function M.format_document(content, options) fb_name_length = #fb_name in_fb_call = true fb_call_indent = indent_level + fb_call_first_line = true end end @@ -221,17 +223,28 @@ function M.format_document(content, options) -- Handle FB call continuation local formatted_line if in_fb_call then - -- Check if line ends an FB call (has closing paren without opening) + -- Check if this is the first line of the FB call + local is_first_line = fb_call_first_line + + -- Check if line ends an FB call (has closing paren) local has_closing = trimmed:match(".*%)") if has_closing and not trimmed:match("%(") then - -- This line closes the FB call - formatted_line = get_continuation_indent() .. trimmed + -- This line closes the FB call - use normal indent + formatted_line = get_indent() .. trimmed in_fb_call = false + fb_call_first_line = false -- Check if this is a continuation line (ends with ,) elseif is_fb_call_continuation(trimmed) then - formatted_line = get_continuation_indent() .. trimmed + if is_first_line then + -- First line of FB call - use normal indent + formatted_line = get_indent() .. trimmed + fb_call_first_line = false + else + -- Continuation line - use continuation indent + formatted_line = get_continuation_indent() .. trimmed + end else - -- Still inside FB call but not a continuation + -- Still inside FB call but not a continuation - use continuation indent formatted_line = get_continuation_indent() .. trimmed end else