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 vertical multiline: fix implicit prefer #3471

Merged
merged 1 commit into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,6 @@ class FormatOps(
case _ => Nil
}).filter(_.pos.start > open.start)

val mixedParams = isBracket && allParenOwners.nonEmpty
val allOwners = lpOwner +: allParenOwners

// find the last param on the defn so that we can apply our `policy`
Expand Down Expand Up @@ -1226,34 +1225,11 @@ class FormatOps(
if shouldNotDangle && !isLeftCommentThenBreak(ftd) =>
Seq(Split(NoSplit, 0))
// Indent separators `)(` and `](` by `indentSep`
case Decision(FormatToken(_, rp: T.RightBracket, m), _)
if lpOwner eq m.rightOwner =>
Seq(Split(Newline, 0).withIndent(indentSep, rp, ExpiresOn.After))
case Decision(FormatToken(_, rp: T.RightParen, m), _)
if allOwners.contains(m.rightOwner) =>
Seq(Split(Newline, 0).withIndent(indentSep, rp, ExpiresOn.After))
// Add a newline after left paren if:
// - There's an implicit keyword and newlineBeforeImplicitKW is enabled
// - newlineAfterOpenParen is enabled
// - Mixed-params case with constructor modifier `] private (`
case Decision(t @ FormatToken(lp: T.LeftParen, right, m), _)
if allOwners.contains(m.leftOwner) =>
val close2 = matching(lp)

// We don't want to create newlines for default values.
def isDefinition = allOwners.contains(owners(close2))

val shouldAddNewline = {
if (right.is[soft.ImplicitOrUsing])
style.newlines.forceBeforeImplicitParamListModifier
else
style.verticalMultiline.newlineAfterOpenParen && isDefinition
} || (mixedParams && prev(t).meta.leftOwner.is[CtorModifier])

Seq(
Split(NoSplit.orNL(!shouldAddNewline), 0)
.withIndent(indentParam, close2, ExpiresOn.Before)
)
case Decision(FormatToken(_, `close`, _), _) =>
Seq(Split(Newline, 0).withIndent(indentSep, close, ExpiresOn.After))
case Decision(FormatToken(LeftParenOrBracket(), _, m), ss)
if allParenOwners.contains(m.leftOwner) =>
ss.filter(!_.isActiveFor(SplitTag.VerticalMultilineSingleLine))
case Decision(ftd @ FormatToken(soft.ImplicitOrUsing(), _, _), _)
if style.newlines.forceAfterImplicitParamListModifier &&
!tokens.isRightCommentThenBreak(ftd) =>
Expand Down Expand Up @@ -1287,8 +1263,14 @@ class FormatOps(
}
val slbSplit = Split(space, 0)
.withSingleLine(slbEnd, killOnFail = true)
.preActivateFor(SplitTag.VerticalMultilineSingleLine)

if (isBracket) {
val noSlbPolicy = Policy.on(lastParen) {
case Decision(FormatToken(LeftParenOrBracket(), _, m), ss)
if allParenOwners.contains(m.leftOwner) =>
ss.filter(!_.isActiveFor(SplitTag.VerticalMultilineSingleLine))
}
val noSplit =
if (allParenOwners.isEmpty)
Split(space, 0).withSingleLine(close)
Expand All @@ -1302,7 +1284,7 @@ class FormatOps(
Split(space, 0).withSingleLine(lpNextLeft).orPolicy(slbPolicy)
}
val nlSplit = Split(Newline, 1, policy = policy).withIndent(firstIndent)
Seq(slbSplit, noSplit, nlSplit)
Seq(slbSplit, noSplit.andPolicy(noSlbPolicy), nlSplit)
} else {
val rightIsImplicit = r.is[soft.ImplicitOrUsing]
val opensImplicit = rightIsImplicit &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ object SplitTag {
case object SelectChainSecondNL extends SplitTag
case object InfixChainNoNL extends SplitTag
case object OnelineWithChain extends SplitTag
case object VerticalMultilineSingleLine extends SplitTag

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def format_![T <: Tree](
foo: Int
)(f: A => B,
k: D
)(implicit ev: Parse[T],
)(implicit
ev: Parse[T],
ev2: EC
): String
<<< #1462
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ def getListing(
b: String,
c: String,
d: String
)(implicit e: String,
)(implicit
e: String,
g: String,
f: String): Future[String] = {
a + b + c + d + e + g + f
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ def format_![T <: Tree](
foo: Int
)(f: A => B,
k: D
)(implicit ev: Parse[T],
)(implicit
ev: Parse[T],
ev2: EC
): String

Expand Down Expand Up @@ -39,7 +40,8 @@ def format_![T <: Tree](
def format_![T <: Tree](
code: String,
code2: String
)(implicit ev: Parse[T],
)(implicit
ev: Parse[T],
ex: D
): String = 1

Expand All @@ -54,7 +56,8 @@ def format_![T <: Tree](
code: String,
foo: Int
)(f: A => B
)(implicit ev: Parse[T],
)(implicit
ev: Parse[T],
ev2: EC
): String

Expand All @@ -71,9 +74,8 @@ def format_![
T <: Tree // Some type comment
](code: String, // The code!
code2: String
)(implicit ev: Parse[
T
], // The Parser!!! Some very long comment that goes over limit
)(implicit
ev: Parse[T], // The Parser!!! Some very long comment that goes over limit
ex: D
): String = 1

Expand Down Expand Up @@ -104,7 +106,8 @@ def format_![T <: Tree](
updatedAt: Instant = Instant.now(),
user: User = new User { def someFunc(): RT = () },
createdAt: Instant = Default.getInstant(a)(b)
)(implicit ev: Parse[T],
)(implicit
ev: Parse[T],
ev2: EC
): String

Expand All @@ -119,7 +122,8 @@ final class UserProfile(
address: Address,
profession: Profession,
school: School
)(implicit ctx: Context,
)(implicit
ctx: Context,
ec: Executor)
extends Profile
with UserSettings
Expand All @@ -133,7 +137,8 @@ override def load()(implicit taskCtx: Context,
): Future[Seq[A] Or B]
>>>
override def load(
)(implicit taskCtx: Context,
)(implicit
taskCtx: Context,
ec: ExecutionContext
): Future[Seq[A] Or B]

Expand All @@ -145,7 +150,8 @@ override def load(code: String)()(implicit taskCtx: Context,
override def load(
code: String
)(
)(implicit taskCtx: Context,
)(implicit
taskCtx: Context,
ec: ExecutionContext
): Future[Seq[A] Or B]

Expand Down