Skip to content

Commit a0d5c4f

Browse files
author
José Valim
committed
Keep the user's choice on parens call with next break fits
Closes #7535 Signed-off-by: José Valim <[email protected]>
1 parent 510ac44 commit a0d5c4f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib/elixir/lib/code/formatter.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,13 +1134,14 @@ defmodule Code.Formatter do
11341134
if left != [] and keyword? and skip_parens? and generators_count == 0 do
11351135
call_args_to_algebra_with_no_parens_keywords(meta, left, right, context, extra, state)
11361136
else
1137-
next_break_fits? = next_break_fits?(right, state)
1138-
last_arg_mode = if next_break_fits?, do: :next_break_fits, else: :none
11391137
force_keyword? = keyword? and force_keyword?(right)
1140-
non_empty_eol? = left != [] and not next_break_fits? and Keyword.get(meta, :eol, false)
1138+
non_empty_eol? = left != [] and Keyword.get(meta, :eol, false)
11411139
join = if generators_count > 1 or force_keyword? or non_empty_eol?, do: :line, else: :glue
11421140
args = if keyword?, do: left ++ right, else: left ++ [right]
11431141

1142+
next_break_fits? = join == :glue and next_break_fits?(right, state)
1143+
last_arg_mode = if next_break_fits?, do: :next_break_fits, else: :none
1144+
11441145
{args_doc, _join, state} =
11451146
args_to_algebra_with_comments(
11461147
args,

lib/elixir/test/elixir/code_formatter/calls_test.exs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,14 @@ defmodule Code.Formatter.CallsTest do
687687

688688
# Doesn't preserve this because only the beginning has a newline
689689
assert_format "Remote.call(\nfoo, bar, baz)", "Remote.call(foo, bar, baz)"
690+
691+
assert_same """
692+
Remote.call(
693+
:hello,
694+
:foo,
695+
fn -> :bar end
696+
)
697+
"""
690698
end
691699
end
692700

0 commit comments

Comments
 (0)