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: tune optimal/killOnFail in binpack parens #4247

Merged
merged 1 commit into from
Sep 12, 2024
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 @@ -1238,7 +1238,12 @@ class Router(formatOps: FormatOps) {
val noSplit =
if (nlOnly) Split.ignored
else if (singleLineOnly || noNLPolicy == null) baseNoSplit
.withSingleLine(close, sjsExclude, noSyntaxNL = true)
.withSingleLine(
close,
sjsExclude,
noSyntaxNL = true,
killOnFail = !dangleCloseDelim,
)
else {
def noSingleArgIndents = oneline || singleArgAsInfix.isDefined ||
!style.binPack.indentCallSiteSingleArg ||
Expand Down Expand Up @@ -1284,7 +1289,12 @@ class Router(formatOps: FormatOps) {
}
unindentPolicy & indentOncePolicy
}
baseNoSplit.withOptimalToken(opt)
val optLite = style.newlines.keep && preferConfigStyle &&
!isSingleArg
val kof = style.newlines.keep && preferConfigStyle && isSingleArg &&
!dangleCloseDelim && singleArgAsInfix.isEmpty
baseNoSplit
.withOptimalToken(opt, recurseOnly = optLite, killOnFail = kof)
.withPolicy(noSplitPolicy & indentPolicy & noNLPolicy())
.withIndents(noSplitIndents)
}
Expand Down
52 changes: 50 additions & 2 deletions scalafmt-tests/src/test/resources/newlines/source_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -8692,7 +8692,7 @@ object a {
barBarBarBarBarBarBar;
val baz = foo
}
<<< SKIP #4133 binpack with complex nested applies and not forcing config style, !dangling
<<< #4133 binpack with complex nested applies and not forcing config style, !dangling
binPack.preset = always
danglingParentheses.preset = false
runner.optimizer {
Expand Down Expand Up @@ -8731,7 +8731,55 @@ object a {
)
}
>>>
FormatTests:54 [e]: org.scalafmt.Error$SearchStateExploded: Search state exploded on '[227] )∙(: RightParen [1072..1073) [] LeftParen [1073..1074)', line 27: exceeded `runner.maxStateVisits` [see https://scalameta.org/scalafmt/docs/configuration.html#search-state-exploded]
object a {
div(cls := "cover")(
div(cls := "doc")(bodyContents),
Option.when(full)(
section(id := "attributes")(
Option.when(
memberTypeParams.nonEmpty)(
Seq(
h2(cls := "h500")(
"Type parameters"),
dl(cls := "attributes")(
memberTypeParams *)
)).toSeq.flatten,
Option.when(
memberValueParams.nonEmpty)(
Seq(
h2(cls := "h500")(
"Value parameters"),
dl(cls := "attributes")(
memberValueParams *)
)).toSeq.flatten,
h2(cls := "h500")("Attributes"),
dl(cls := "attributes")(
attributes *)
)
).getOrElse(
Option.when(
memberTypeParams.nonEmpty)(
Seq(
h2(cls := "h200")(
"Type parameters"),
dl(cls := "attributes attributes-small")(
memberTypeParams *)
)).toSeq.flatten ++
Option.when(
memberValueParams.nonEmpty)(
Seq(
h2(cls := "h200")(
"Value parameters"),
dl(cls := "attributes attributes-small")(
memberValueParams *)
)).toSeq.flatten :+
h2(cls := "h200")(
"Attributes") :+
dl(cls := "attributes attributes-small")(
attributes *)
)
)
}
<<< #4133 binpack with complex nested applies and not forcing config style, dangling
binPack.preset = always
danglingParentheses.preset = true
Expand Down
65 changes: 63 additions & 2 deletions scalafmt-tests/src/test/resources/newlines/source_unfold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -8936,7 +8936,7 @@ object a {
val foo = barBarBarBarBarBarBar;
val baz = foo
}
<<< SKIP #4133 binpack with complex nested applies and not forcing config style, !dangling
<<< #4133 binpack with complex nested applies and not forcing config style, !dangling
binPack.preset = always
danglingParentheses.preset = false
runner.optimizer {
Expand Down Expand Up @@ -8975,7 +8975,68 @@ object a {
)
}
>>>
FormatTests:54 [e]: org.scalafmt.Error$SearchStateExploded: Search state exploded on '[227] )∙(: RightParen [1072..1073) [] LeftParen [1073..1074)', line 27: exceeded `runner.maxStateVisits` [see https://scalameta.org/scalafmt/docs/configuration.html#search-state-exploded]
object a {
div(cls := "cover")(
div(cls := "doc")(bodyContents),
Option
.when(full)(
section(id := "attributes")(
Option
.when(
memberTypeParams
.nonEmpty)(
Seq(
h2(cls := "h500")(
"Type parameters"),
dl(cls := "attributes")(
memberTypeParams *)))
.toSeq
.flatten,
Option
.when(
memberValueParams
.nonEmpty)(
Seq(
h2(cls := "h500")(
"Value parameters"),
dl(cls := "attributes")(
memberValueParams *)))
.toSeq
.flatten,
h2(cls := "h500")(
"Attributes"),
dl(cls := "attributes")(
attributes *)))
.getOrElse(
Option
.when(
memberTypeParams.nonEmpty)(
Seq(
h2(cls := "h200")(
"Type parameters"),
dl(
cls := "attributes attributes-small")(
memberTypeParams *)))
.toSeq
.flatten ++
Option
.when(
memberValueParams
.nonEmpty)(
Seq(
h2(cls := "h200")(
"Value parameters"),
dl(
cls := "attributes attributes-small")(
memberValueParams *)))
.toSeq
.flatten :+
h2(cls := "h200")(
"Attributes") :+
dl(
cls := "attributes attributes-small")(
attributes *)))
}
<<< #4133 binpack with complex nested applies and not forcing config style, dangling
binPack.preset = always
danglingParentheses.preset = true
Expand Down
43 changes: 28 additions & 15 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -6780,9 +6780,10 @@ object a:
def foo =
for template <- templates do
val current_Map_String__Object =
template_templateFile_settings_getOrElse("page", Map.empty).asInstanceOf[
Map_String_Object
]
template_templateFile_settings_getOrElse(
"page",
Map.empty
).asInstanceOf[Map_String_Object]
<<< scala.js overflow within for-yield !dangling
binPack.preset = always
danglingParentheses.preset = false
Expand All @@ -6796,8 +6797,8 @@ object a:
def foo =
for template <- templates do
val current_Map_String__Object =
template_templateFile_settings_getOrElse("page", Map.empty).asInstanceOf[
Map_String_Object]
template_templateFile_settings_getOrElse(
"page", Map.empty).asInstanceOf[Map_String_Object]
<<< #4133 for-yield with rewritten body
rewrite.scala3.removeOptionalBraces = yes
===
Expand Down Expand Up @@ -7079,10 +7080,15 @@ object a:
object a:
if (args.isEmpty) {
run(insertClasspathInArgs(args1,
List(dottyCompiler, dottyInterfaces, asm, dottyStaging,
dottyTastyInspector, tastyCore, compilerInterface).mkString(
File.pathSeparator
)))
List(
dottyCompiler,
dottyInterfaces,
asm,
dottyStaging,
dottyTastyInspector,
tastyCore,
compilerInterface
).mkString(File.pathSeparator)))
} else run(args)
<<< #4133 overflow apply/selects with binpack, dangling
maxColumn = 70
Expand All @@ -7098,10 +7104,15 @@ object a:
if (args.isEmpty) {
run(insertClasspathInArgs(
args1,
List(dottyCompiler, dottyInterfaces, asm, dottyStaging,
dottyTastyInspector, tastyCore, compilerInterface).mkString(
File.pathSeparator
).mkString(File.pathSeparator)
List(
dottyCompiler,
dottyInterfaces,
asm,
dottyStaging,
dottyTastyInspector,
tastyCore,
compilerInterface
).mkString(File.pathSeparator).mkString(File.pathSeparator)
))
} else run(args)
<<< #4133 overflow apply with binpack, !dangling
Expand Down Expand Up @@ -7149,11 +7160,13 @@ object a:
>>>
object a:
if (args.isEmpty) {
run(insertClasspathInArgs(
run(
insertClasspathInArgs(
args1,
List(dottyCompiler, dottyInterfaces, asm, dottyStaging,
dottyTastyInspector, tastyCore, compilerInterface).mkString(
File.pathSeparator).mkString(File.pathSeparator)
File.pathSeparator).mkString(
File.pathSeparator)
))
} else run(args)
<<< #4133 overflow select with binpack, dangling
Expand Down
Loading