diff --git a/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt b/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt index 68c5ab91..fa5b3216 100644 --- a/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt +++ b/pkl-formatter/src/main/kotlin/org/pkl/formatter/Builder.kt @@ -601,7 +601,7 @@ internal class Builder(sourceText: String, private val grammarVersion: GrammarVe val splitIndex = children.indexOfLast { it.type in SAME_LINE_EXPRS } val normalParams = children.subList(0, splitIndex) val lastParam = children.subList(splitIndex, children.size) - val trailingNode = if (endsWithClosingBracket(children[splitIndex])) Empty else line() + val trailingNode = if (endsWithClosingBracket(lastParam.last())) Empty else line() val lastNodes = formatGeneric(lastParam, spaceOrLine()) if (normalParams.isEmpty()) { group(Group(newId(), lastNodes), trailingNode) @@ -619,7 +619,7 @@ internal class Builder(sourceText: String, private val grammarVersion: GrammarVe return if (node.children.isNotEmpty()) { endsWithClosingBracket(node.children.last()) } else { - node.isTerminal("}") + node.isTerminal("}") || node.type.isAffix } } @@ -1328,7 +1328,6 @@ internal class Builder(sourceText: String, private val grammarVersion: GrammarVe } private fun hasTrailingAffix(node: Node, next: Node): Boolean { - if (node.isMultiline()) return false var n: Node? = next while (n != null) { if (n.type.isAffix && node.span.lineEnd == n.span.lineBegin) return true diff --git a/pkl-formatter/src/test/files/FormatterSnippetTests/input/line-breaks.pkl b/pkl-formatter/src/test/files/FormatterSnippetTests/input/line-breaks.pkl index 623f91ce..69403679 100644 --- a/pkl-formatter/src/test/files/FormatterSnippetTests/input/line-breaks.pkl +++ b/pkl-formatter/src/test/files/FormatterSnippetTests/input/line-breaks.pkl @@ -63,11 +63,10 @@ local function render(currentIndent: String) = "\(currentIndent)@\(identifier.render(currentIndent))" + if (body == null) "" else " " + body.render(currentIndent) -// FIXME: output is currently unstable -// items: List = -// allItems -// .filter((item) -> -// badItems.containsKey(item) // some line comment -// || item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment -// ) -// .sortBy((item) -> item.name) +items: List = + allItems + .filter((item) -> + badItems.containsKey(item) // some line comment + || item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment + ) + .sortBy((item) -> item.name) diff --git a/pkl-formatter/src/test/files/FormatterSnippetTests/output/line-breaks.pkl b/pkl-formatter/src/test/files/FormatterSnippetTests/output/line-breaks.pkl index a5cd1ffb..cfce478f 100644 --- a/pkl-formatter/src/test/files/FormatterSnippetTests/output/line-breaks.pkl +++ b/pkl-formatter/src/test/files/FormatterSnippetTests/output/line-breaks.pkl @@ -74,11 +74,10 @@ local function render(currentIndent: String) = "\(currentIndent)@\(identifier.render(currentIndent))" + if (body == null) "" else " " + body.render(currentIndent) -// FIXME: output is currently unstable -// items: List = -// allItems -// .filter((item) -> -// badItems.containsKey(item) // some line comment -// || item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment -// ) -// .sortBy((item) -> item.name) +items: List = + allItems + .filter((item) -> + badItems.containsKey(item) // some line comment + || item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment + ) + .sortBy((item) -> item.name)