summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2018-04-06 15:30:07 +0200
committerJosé Valim <jose.valim@plataformatec.com.br>2018-04-06 15:30:09 +0200
commitcb67649dff375c662d6e915205df2134b78966af (patch)
tree894ef30ce7b40618488ced3ad227e0555e576b87
parent584799809a1cbc3dabe5c19365e4fd44a647c383 (diff)
downloadelixir-cb67649dff375c662d6e915205df2134b78966af.tar.gz
Keep the user's choice on parens call with next break fits
Closes #7535
-rw-r--r--lib/elixir/lib/code/formatter.ex7
-rw-r--r--lib/elixir/test/elixir/code_formatter/calls_test.exs8
2 files changed, 12 insertions, 3 deletions
diff --git a/lib/elixir/lib/code/formatter.ex b/lib/elixir/lib/code/formatter.ex
index d426ddaf6..4f401587b 100644
--- a/lib/elixir/lib/code/formatter.ex
+++ b/lib/elixir/lib/code/formatter.ex
@@ -1136,13 +1136,14 @@ defmodule Code.Formatter do
if left != [] and keyword? and skip_parens? and generators_count == 0 do
call_args_to_algebra_with_no_parens_keywords(meta, left, right, context, extra, state)
else
- next_break_fits? = next_break_fits?(right, state)
- last_arg_mode = if next_break_fits?, do: :next_break_fits, else: :none
force_keyword? = keyword? and force_keyword?(right)
- non_empty_eol? = left != [] and not next_break_fits? and Keyword.get(meta, :eol, false)
+ non_empty_eol? = left != [] and Keyword.get(meta, :eol, false)
join = if generators_count > 1 or force_keyword? or non_empty_eol?, do: :line, else: :glue
args = if keyword?, do: left ++ right, else: left ++ [right]
+ next_break_fits? = join == :glue and next_break_fits?(right, state)
+ last_arg_mode = if next_break_fits?, do: :next_break_fits, else: :none
+
{args_doc, _join, state} =
args_to_algebra_with_comments(
args,
diff --git a/lib/elixir/test/elixir/code_formatter/calls_test.exs b/lib/elixir/test/elixir/code_formatter/calls_test.exs
index 49ee42138..e4f7a0422 100644
--- a/lib/elixir/test/elixir/code_formatter/calls_test.exs
+++ b/lib/elixir/test/elixir/code_formatter/calls_test.exs
@@ -687,6 +687,14 @@ defmodule Code.Formatter.CallsTest do
# Doesn't preserve this because only the beginning has a newline
assert_format "Remote.call(\nfoo, bar, baz)", "Remote.call(foo, bar, baz)"
+
+ assert_same """
+ Remote.call(
+ :hello,
+ :foo,
+ fn -> :bar end
+ )
+ """
end
end