mirror of
https://github.com/apple/pkl.git
synced 2026-07-07 21:45:22 +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 splitIndex = children.indexOfLast { it.type in SAME_LINE_EXPRS }
|
||||||
val normalParams = children.subList(0, splitIndex)
|
val normalParams = children.subList(0, splitIndex)
|
||||||
val lastParam = children.subList(splitIndex, children.size)
|
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())
|
val lastNodes = formatGeneric(lastParam, spaceOrLine())
|
||||||
if (normalParams.isEmpty()) {
|
if (normalParams.isEmpty()) {
|
||||||
group(Group(newId(), lastNodes), trailingNode)
|
group(Group(newId(), lastNodes), trailingNode)
|
||||||
@@ -619,7 +619,7 @@ internal class Builder(sourceText: String, private val grammarVersion: GrammarVe
|
|||||||
return if (node.children.isNotEmpty()) {
|
return if (node.children.isNotEmpty()) {
|
||||||
endsWithClosingBracket(node.children.last())
|
endsWithClosingBracket(node.children.last())
|
||||||
} else {
|
} 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 {
|
private fun hasTrailingAffix(node: Node, next: Node): Boolean {
|
||||||
if (node.isMultiline()) return false
|
|
||||||
var n: Node? = next
|
var n: Node? = next
|
||||||
while (n != null) {
|
while (n != null) {
|
||||||
if (n.type.isAffix && node.span.lineEnd == n.span.lineBegin) return true
|
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))" +
|
"\(currentIndent)@\(identifier.render(currentIndent))" +
|
||||||
if (body == null) "" else " " + body.render(currentIndent)
|
if (body == null) "" else " " + body.render(currentIndent)
|
||||||
|
|
||||||
// FIXME: output is currently unstable
|
items: List<Item> =
|
||||||
// items: List<Item> =
|
allItems
|
||||||
// allItems
|
.filter((item) ->
|
||||||
// .filter((item) ->
|
badItems.containsKey(item) // some line comment
|
||||||
// badItems.containsKey(item) // some line comment
|
|| item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment
|
||||||
// || item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment
|
)
|
||||||
// )
|
.sortBy((item) -> item.name)
|
||||||
// .sortBy((item) -> item.name)
|
|
||||||
|
|||||||
@@ -74,11 +74,10 @@ local function render(currentIndent: String) =
|
|||||||
"\(currentIndent)@\(identifier.render(currentIndent))"
|
"\(currentIndent)@\(identifier.render(currentIndent))"
|
||||||
+ if (body == null) "" else " " + body.render(currentIndent)
|
+ if (body == null) "" else " " + body.render(currentIndent)
|
||||||
|
|
||||||
// FIXME: output is currently unstable
|
items: List<Item> =
|
||||||
// items: List<Item> =
|
allItems
|
||||||
// allItems
|
.filter((item) ->
|
||||||
// .filter((item) ->
|
badItems.containsKey(item) // some line comment
|
||||||
// badItems.containsKey(item) // some line comment
|
|| item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment
|
||||||
// || item.tags.toList().findOrNull((it) -> it.type == "bookmark") != null // some other line comment
|
)
|
||||||
// )
|
.sortBy((item) -> item.name)
|
||||||
// .sortBy((item) -> item.name)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user