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

Router: extension is probably also a keyword #3507

Merged
merged 3 commits into from
Mar 15, 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 @@ -680,9 +680,10 @@ class Router(formatOps: FormatOps) {
isSymbolicName(name.value) && name.parent.exists(isDefDef) =>
Space
case _: Defn.ExtensionGroup if left.is[soft.KwExtension] =>
Space
Space(style.spaces.afterKeywordBeforeParen)
case _ => Space(left.is[T.Comment])
}
def baseNoSplit(implicit fileLine: FileLine) = Split(modification, 0)
val defn = isParamClauseSite(rightOwner)
val defRhs = if (defn) defDefBodyParent(rightOwner) else None
val beforeDefRhs = defRhs.flatMap(tokens.tokenJustBeforeOpt)
Expand All @@ -696,8 +697,8 @@ class Router(formatOps: FormatOps) {
val isAlignFirstParen = shouldAlignBefore(style.align) &&
!prevNonComment(ft).left.is[T.RightParen]
def noSplitSplit(implicit fileLine: FileLine) =
if (isAlignFirstParen) Split(NoSplit, 0)
else Split(NoSplit, 0).withSingleLine(close)
if (isAlignFirstParen) baseNoSplit
else baseNoSplit.withSingleLine(close)
val splits = src match {
case Newlines.unfold =>
val rightParent = rightOwner.parent.get
Expand All @@ -716,7 +717,7 @@ class Router(formatOps: FormatOps) {
case _ => NoPolicy
}
Seq(
Split(NoSplit, 0).withSingleLine(slbEnd),
baseNoSplit.withSingleLine(slbEnd),
Split(Newline, 1)
.withIndent(indent)
.withPolicy(
Expand Down Expand Up @@ -804,7 +805,7 @@ class Router(formatOps: FormatOps) {
}
}
else None
beforeOpenParenSplits.getOrElse(Seq(Split(modification, 0)))
beforeOpenParenSplits.getOrElse(Seq(baseNoSplit))

// Defn.{Object, Class, Trait, Enum}
case FormatToken(
Expand Down
30 changes: 30 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/Extension.stat
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,33 @@ object Dictionary:
dict.selectDynamic(key).asInstanceOf[A]
def update(key: String, value: A): Unit =
dict.updateDynamic(key)(value.asInstanceOf[js.Any])
<<< #3499 1
spaces.afterKeywordBeforeParen = true
===
extension (s: String)
def foo(): Unit = ???
>>>
extension (s: String) def foo(): Unit = ???
<<< #3499 2
spaces.afterKeywordBeforeParen = true
newlines.beforeOpenParenDefnSite = unfold
===
extension (s: String)
def foo(): Unit = ???
>>>
extension (s: String) def foo(): Unit = ???
<<< #3499 3
spaces.afterKeywordBeforeParen = false
===
extension (s: String)
def foo(): Unit = ???
>>>
extension(s: String) def foo(): Unit = ???
<<< #3499 4
spaces.afterKeywordBeforeParen = false
newlines.beforeOpenParenDefnSite = unfold
===
extension (s: String)
def foo(): Unit = ???
>>>
extension(s: String) def foo(): Unit = ???