-
Notifications
You must be signed in to change notification settings - Fork 338
Adjust formatting of line comments in lets #1256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
3920f46 to
2cb2529
Compare
| node.children, | ||
| { _, next -> if (next.type == NodeType.LET_PARAMETER_DEFINITION) Space else spaceOrLine() }, | ||
| ) { node, next -> | ||
| if (next == null) { | ||
| if (node.type == NodeType.LET_EXPR) { | ||
| when { | ||
| node.type == NodeType.LET_EXPR -> { | ||
| // unpack the lets | ||
| val group = formatLetExpr(node) as Group | ||
| Nodes(group.nodes) | ||
| } else indent(format(node)) | ||
| } else format(node) | ||
| } | ||
| node.type == NodeType.LET_PARAMETER_DEFINITION || | ||
| node.isTerminal("let") || | ||
| next?.type == NodeType.LET_EXPR -> format(node) | ||
| else -> indent(format(node)) | ||
| } | ||
| } | ||
| return Group(newId(), nodes) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there, but you can't rely on next?.type == LET_EXPR because you might have more than one comment (in fact you should add this case to the tests):
let (x = 1)
// comment1
// comment2
xProbably easier to check if the expression is another let and just indent based on that:
private fun formatLetExpr(node: Node): FormatNode {
val endsWithLet = node.children.last().type == NodeType.LET_EXPR
val nodes =
formatGenericWithGen(
node.children,
{ _, next -> if (next.type == NodeType.LET_PARAMETER_DEFINITION) Space else spaceOrLine() },
) { node, _ ->
when {
node.type == NodeType.LET_EXPR -> {
// unpack the lets
val group = formatLetExpr(node) as Group
Nodes(group.nodes)
}
endsWithLet -> format(node)
node.type.isExpression || node.type.isAffix -> indent(format(node))
else -> format(node)
}
}
return Group(newId(), nodes)
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks!
6c14ac1 to
8e8e8d8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Fixes an issue where line comments preceding let bodies are not indented.
Turn this:
Into this: