Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/elixir/lib/calendar/date_range.ex
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,12 @@ defmodule Date.Range do
when step < 0 and first_days < last_days,
do: 0

defp size(%Date.Range{first_in_iso_days: first_days, last_in_iso_days: last_days, step: step}),
do: abs(div(last_days - first_days, step)) + 1
defp size(%Date.Range{
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was going over the line limit.

first_in_iso_days: first_days,
last_in_iso_days: last_days,
step: step
}),
do: abs(div(last_days - first_days, step)) + 1

# TODO: Remove me on v2.0
defp size(
Expand Down
50 changes: 29 additions & 21 deletions lib/elixir/lib/code/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -617,9 +617,12 @@ defmodule Code.Formatter do
end

doc =
with_next_break_fits(next_break_fits?(right_arg, state), right, fn right ->
concat(group(left), group(nest(glue(op, group(right)), 2, :break)))
end)
concat(
group(left),
with_next_break_fits(next_break_fits?(right_arg, state), right, fn right ->
nest(glue(op, right), 2, :break)
end)
)

{doc, state}
end
Expand Down Expand Up @@ -818,9 +821,8 @@ defmodule Code.Formatter do

{" " <> op_string,
with_next_break_fits(next_break_fits?, right, fn right ->
right = nest(concat(break(), group(right)), nesting, :break)
right = if eol?, do: force_unfit(right), else: right
group(right)
right = nest(concat(break(), right), nesting, :break)
if eol?, do: force_unfit(right), else: right
end)}
end

Expand Down Expand Up @@ -1262,16 +1264,15 @@ defmodule Code.Formatter do
args_doc =
if skip_parens? do
left_doc
|> concat(next_break_fits(group(right_doc, :inherit), :enabled))
|> concat(group(right_doc, :optimistic))
|> nest(:cursor, :break)
else
right_doc =
right_doc
|> nest(2, :break)
|> concat(break(""))
|> concat(")")
|> group(:inherit)
|> next_break_fits(:enabled)
|> group(:optimistic)

concat(nest(left_doc, 2, :break), right_doc)
end
Expand Down Expand Up @@ -1314,27 +1315,24 @@ defmodule Code.Formatter do
|> concat(args_doc)
|> nest(2)
|> concat(extra)
|> group()

skip_parens? ->
" "
|> concat(args_doc)
|> concat(extra)
|> group()

true ->
"("
|> concat(break(""))
|> nest(2, :break)
|> concat(args_doc)
|> concat(extra)
|> group()
end

if next_break_fits? do
{next_break_fits(doc, :disabled), state}
{group(doc, :pessimistic), state}
else
{doc, state}
{group(doc), state}
end
end

Expand Down Expand Up @@ -1800,10 +1798,17 @@ defmodule Code.Formatter do

doc =
case args do
[_ | _] -> concat_to_last_group(doc, ",")
[] when last_arg_mode == :force_comma -> concat_to_last_group(doc, ",")
[] when last_arg_mode == :next_break_fits -> next_break_fits(doc, :enabled)
[] when last_arg_mode == :none -> doc
[_ | _] ->
concat_to_last_group(doc, ",")

[] when last_arg_mode == :force_comma ->
concat_to_last_group(doc, ",")

[] when last_arg_mode == :next_break_fits ->
doc |> ungroup_if_group() |> group(:optimistic)

[] when last_arg_mode == :none ->
doc
end

{{doc, @empty, 1}, state}
Expand Down Expand Up @@ -2321,11 +2326,14 @@ defmodule Code.Formatter do
defp with_next_break_fits(condition, doc, fun) do
if condition do
doc
|> next_break_fits(:enabled)
|> group(:optimistic)
|> fun.()
|> next_break_fits(:disabled)
|> group(:pessimistic)
else
fun.(doc)
doc
|> group()
|> fun.()
|> group()
end
end

Expand Down
Loading
Loading