fix(formatter): Fix FB call indentation logic

- Track first line of FB call separately with fb_call_first_line flag
- First line of FB call uses normal indent
- Continuation lines use continuation indent (base + fb_name_length + 2)
- Closing line uses normal indent
- Parameters now align correctly
This commit is contained in:
2026-02-18 15:05:13 +01:00
parent eb11380aea
commit 5b5d9c46f6
+18 -5
View File
@@ -72,6 +72,7 @@ function M.format_document(content, options)
local in_fb_call = false local in_fb_call = false
local fb_call_indent = 0 local fb_call_indent = 0
local fb_name_length = 0 local fb_name_length = 0
local fb_call_first_line = false
local function get_indent() local function get_indent()
return string.rep(indent_char, indent_level * indent_size) return string.rep(indent_char, indent_level * indent_size)
@@ -204,6 +205,7 @@ function M.format_document(content, options)
fb_name_length = #fb_name fb_name_length = #fb_name
in_fb_call = true in_fb_call = true
fb_call_indent = indent_level fb_call_indent = indent_level
fb_call_first_line = true
end end
end end
@@ -221,17 +223,28 @@ function M.format_document(content, options)
-- Handle FB call continuation -- Handle FB call continuation
local formatted_line local formatted_line
if in_fb_call then 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(".*%)") local has_closing = trimmed:match(".*%)")
if has_closing and not trimmed:match("%(") then if has_closing and not trimmed:match("%(") then
-- This line closes the FB call -- This line closes the FB call - use normal indent
formatted_line = get_continuation_indent() .. trimmed formatted_line = get_indent() .. trimmed
in_fb_call = false in_fb_call = false
fb_call_first_line = false
-- Check if this is a continuation line (ends with ,) -- Check if this is a continuation line (ends with ,)
elseif is_fb_call_continuation(trimmed) then 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 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 formatted_line = get_continuation_indent() .. trimmed
end end
else else