diff --git a/src/formatter.lua b/src/formatter.lua index b4696e1..69f2473 100644 --- a/src/formatter.lua +++ b/src/formatter.lua @@ -78,8 +78,11 @@ function M.format_document(content, options) end local function get_continuation_indent() - -- Continuation is one additional indent level beyond current - return string.rep(indent_char, (indent_level + 1) * indent_size) + -- Continuation indent to align parameters + -- Aligns parameter name with position after FB name + opening paren + -- Formula: base indent + FB name length + 1 (for opening paren) + 1 (extra offset) + local base_indent = string.rep(indent_char, indent_level * indent_size) + return base_indent .. string.rep(" ", fb_name_length + 2) end local function get_keyword(line) @@ -218,15 +221,18 @@ function M.format_document(content, options) -- Handle FB call continuation local formatted_line if in_fb_call then - -- Check if this ends the FB call - if not is_fb_call_inside(trimmed) then + -- Check if line ends an FB call (has closing paren without opening) + 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 in_fb_call = false - -- Check if this is a continuation line + -- Check if this is a continuation line (ends with ,) elseif is_fb_call_continuation(trimmed) then formatted_line = get_continuation_indent() .. trimmed else - formatted_line = get_indent() .. trimmed + -- Still inside FB call but not a continuation + formatted_line = get_continuation_indent() .. trimmed end else formatted_line = get_indent() .. trimmed