mirror of
https://github.com/apple/pkl.git
synced 2026-04-24 09:18:35 +02:00
Make formatter stable (#1273)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<Item> =
|
||||
// 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<Item> =
|
||||
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)
|
||||
|
||||
@@ -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<Item> =
|
||||
// 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<Item> =
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user