Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatOps: handle fewer braces and refined types #3446

Merged
merged 2 commits into from
Jan 23, 2023

Conversation

kitbellew
Copy link
Collaborator

@kitbellew kitbellew commented Jan 21, 2023

Fixes #3447.

Comment on lines 3606 to 3627
def f(): Unit =
List(1, 2, 3).foo: a =>
a + 2
.apply:
12 + 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def f(): Unit =
List(1, 2, 3).foo: a =>
a + 2
.apply:
12 + 3
def f(): Unit =
List(1, 2, 3).foo: a =>
a + 2
.apply:
12 + 3

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it comes from the rule which adds indent to first NL before a dot (so that it's indented relative to the beginning of the full expression), and your proposal will be inconsistent with the formatting so far:

   // short maxColumn
   def f(): Unit =
     List(1, 2, 3).foo(a =>
       a + 2)
       .apply(
         12 + 3)
   // longer maxColumn
   def f(): Unit =
     List(1, 2, 3).foo(a => a + 2)
       .apply(12 + 3)
   // there's no NL before a dot
   def f(): Unit =
     List(1, 2, 3).foo { a =>
       a + 2
     }.apply {
       12 + 3
     }
   // there's a NL before a dot
   def f(): Unit =
     List(1, 2, 3).foo { a =>
       a + 2
     } //
       .apply {
         12 + 3
       }

i didn't like this formatting for fold (no proper unindent before select) and forced NL before the first dot if there's a second select. i could do the same for classic (but not keep).

i could try formatting it like this if you prefer:

   // short maxColumn
   def f(): Unit =
     List(1, 2, 3).foo: a =>
         a + 2
       .apply:
         12 + 3)
   // but, should we still do this?
   def f(): Unit =
     List(1, 2, 3).foo: a =>
       a + 2

Copy link
Contributor

Choose a reason for hiding this comment

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

Ach right, I didn't realize it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

slightly modified, tried testing with significant indentation smaller than main indentation, and ran into incorrect parsing problems, so ensure that body is indented relative to subsequent select.

Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect code generated when formatting valid code using fewer braces syntax
2 participants