mirror of
https://github.com/apple/pkl.git
synced 2026-04-19 23:11:29 +02:00
Adjust formatting of line comments in lets (#1256)
This commit is contained in:
@@ -972,18 +972,22 @@ internal class Builder(sourceText: String, private val grammarVersion: GrammarVe
|
|||||||
|
|
||||||
private fun formatLetExpr(node: Node): FormatNode {
|
private fun formatLetExpr(node: Node): FormatNode {
|
||||||
val separator = if (node.isMultiline()) forceLine() else spaceOrLine()
|
val separator = if (node.isMultiline()) forceLine() else spaceOrLine()
|
||||||
|
val endsWithLet = node.children.last().type == NodeType.LET_EXPR
|
||||||
val nodes =
|
val nodes =
|
||||||
formatGenericWithGen(
|
formatGenericWithGen(
|
||||||
node.children,
|
node.children,
|
||||||
{ _, next -> if (next.type == NodeType.LET_PARAMETER_DEFINITION) Space else separator },
|
{ _, next -> if (next.type == NodeType.LET_PARAMETER_DEFINITION) Space else separator },
|
||||||
) { node, next ->
|
) { node, _ ->
|
||||||
if (next == null) {
|
when {
|
||||||
if (node.type == NodeType.LET_EXPR) {
|
node.type == NodeType.LET_EXPR -> {
|
||||||
// unpack the lets
|
// unpack the lets
|
||||||
val group = formatLetExpr(node) as Group
|
val group = formatLetExpr(node) as Group
|
||||||
Nodes(group.nodes)
|
Nodes(group.nodes)
|
||||||
} else indent(format(node))
|
}
|
||||||
} else format(node)
|
endsWithLet -> format(node)
|
||||||
|
node.type.isExpression || node.type.isAffix -> indent(format(node))
|
||||||
|
else -> format(node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return Group(newId(), nodes)
|
return Group(newId(), nodes)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,3 +29,46 @@ bar2 = ( // some comment
|
|||||||
foo, bar
|
foo, bar
|
||||||
// another comment
|
// another comment
|
||||||
) -> foo + bar
|
) -> foo + bar
|
||||||
|
|
||||||
|
bar3 =
|
||||||
|
let (bar = new Dynamic {})
|
||||||
|
// some coment
|
||||||
|
(bar) {
|
||||||
|
qux = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
bar4 =
|
||||||
|
// some coment
|
||||||
|
let (bar = new Dynamic {})
|
||||||
|
(bar) {
|
||||||
|
qux = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
bar5 =
|
||||||
|
let (bar = 4)
|
||||||
|
// some coment
|
||||||
|
let (qux = 5)
|
||||||
|
bar + qux
|
||||||
|
|
||||||
|
bar6 =
|
||||||
|
let (bar = 4)
|
||||||
|
/* some comment */ bar + 5
|
||||||
|
|
||||||
|
bar7 =
|
||||||
|
let (bar = 4) /* some comment */
|
||||||
|
bar + 5
|
||||||
|
|
||||||
|
bar8 =
|
||||||
|
let (bar = 4)
|
||||||
|
// some comment
|
||||||
|
// another comment
|
||||||
|
let (foo = 5)
|
||||||
|
// some comment
|
||||||
|
// another comment
|
||||||
|
bar + foo
|
||||||
|
|
||||||
|
bar9 =
|
||||||
|
let (bar = 4)
|
||||||
|
// some comment
|
||||||
|
// another comment
|
||||||
|
bar
|
||||||
|
|||||||
@@ -32,3 +32,46 @@ bar2 = ( // some comment
|
|||||||
bar
|
bar
|
||||||
// another comment
|
// another comment
|
||||||
) -> foo + bar
|
) -> foo + bar
|
||||||
|
|
||||||
|
bar3 =
|
||||||
|
let (bar = new Dynamic {})
|
||||||
|
// some coment
|
||||||
|
(bar) {
|
||||||
|
qux = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
bar4 =
|
||||||
|
// some coment
|
||||||
|
let (bar = new Dynamic {})
|
||||||
|
(bar) {
|
||||||
|
qux = 4
|
||||||
|
}
|
||||||
|
|
||||||
|
bar5 =
|
||||||
|
let (bar = 4)
|
||||||
|
// some coment
|
||||||
|
let (qux = 5)
|
||||||
|
bar + qux
|
||||||
|
|
||||||
|
bar6 =
|
||||||
|
let (bar = 4)
|
||||||
|
/* some comment */ bar + 5
|
||||||
|
|
||||||
|
bar7 =
|
||||||
|
let (bar = 4) /* some comment */
|
||||||
|
bar + 5
|
||||||
|
|
||||||
|
bar8 =
|
||||||
|
let (bar = 4)
|
||||||
|
// some comment
|
||||||
|
// another comment
|
||||||
|
let (foo = 5)
|
||||||
|
// some comment
|
||||||
|
// another comment
|
||||||
|
bar + foo
|
||||||
|
|
||||||
|
bar9 =
|
||||||
|
let (bar = 4)
|
||||||
|
// some comment
|
||||||
|
// another comment
|
||||||
|
bar
|
||||||
|
|||||||
Reference in New Issue
Block a user