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: improve binpacking parentConstructors #3094

Merged
merged 2 commits into from
Feb 4, 2022

Conversation

kitbellew
Copy link
Collaborator

Alternative to #3091.

@kitbellew kitbellew requested a review from dos65 February 1, 2022 08:27
Comment on lines 128 to 131
object CoreReflection extends {
val u: ru.type = ru
val mirror: u.Mirror = u.runtimeMirror(classOf[scala.meta.Tree].getClassLoader)
} with scala.meta.internal.trees.Reflection with scala.meta.internal.tokens.Reflection
Copy link
Member

Choose a reason for hiding this comment

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

it only fixes extends position.
early stats and } with .. shouldn't be indented

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why shouldn't they be indented? everything between the beginning of a template and the opening brace of its body should be indented.

in your case,

... {
      val u: ru.type = ru
      val mirror: u.Mirror = u.runtimeMirror(classOf[scala.meta.Tree].getClassLoader)
    }

is not the body of CoreReflection but of some other (parent) construct. definitely has to be indented.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

If we treat that parentConstructor doesn't affect early init body and work only for extends and with chain it wouldn't be contrary.

Let me try to fix it it properly, I didn't noticed that there is such setting at the moment when I was preparing a fix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

can you explain how init body is different? other than indentation, what else would you like to do?

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.

The changes to early initializers look good, but I wonder if anything should have been also updated?

@@ -54,8 +54,7 @@ private class Encoder extends CharsetEncoder(
}
>>>
object a {
private class Encoder
extends CharsetEncoder(UTF_16_Common.this, 2.0f, 2.0f,
private class Encoder extends CharsetEncoder(UTF_16_Common.this, 2.0f, 2.0f,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change intended?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes, same explanation is above. always attempts to binpack as much as possible unless there was an explicit break.

case Bar
extends Foo(1) with X
with Y with Z
case Bar extends Foo(1)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems wrong now. With binPack.parentConstructors = Always wasn't the previous state correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the new approach allows space if source is ignored (i.e. fold/unfold) or space was used in the source. in this example (line 128), there was no break here, so extends is also binpacked.

Relax single-line formatting to exclude delimited ranges (parent ctor
args or early-init block) in a few cases.
@kitbellew
Copy link
Collaborator Author

just for visual effect, here's a version which avoids indenting early ctors: in my view, the formatting is not especially readable or pleasing, the dissonance with subsequent parents is prominent:

kitbellew@ce42c5e

Copy link
Member

@dos65 dos65 left a comment

Choose a reason for hiding this comment

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

👍

@kitbellew kitbellew merged commit b7aee3d into scalameta:master Feb 4, 2022
@kitbellew kitbellew deleted the 3091 branch February 4, 2022 15:40
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.

3 participants