Make formatter stable (#1273)

This commit is contained in:
Islon Scherer
2025-10-31 18:58:22 +01:00
committed by GitHub
parent ea778a7e7a
commit 50541d9cda
3 changed files with 16 additions and 19 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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)