in src/main/kotlin/org/arend/formatting/block/SimpleArendBlock.kt [38:160]
override fun getSpacing(child1: Block?, child2: Block): Spacing? {
val nodePsi = myNode.psi
if (nodePsi is ArendFunctionClauses) {
if (child2 is SimpleArendBlock && child2.node.elementType == PIPE) return oneCrlf
}
if (nodePsi is ArendFunctionClauses || nodePsi is ArendFunctionBody && nodePsi.kind == ArendFunctionBody.Kind.COCLAUSE) {
if ((child1 is AbstractArendBlock && child1.node.elementType == LBRACE) xor (child2 is AbstractArendBlock && child2.node.elementType == RBRACE))
return oneCrlf
}
if (nodePsi is ArendFunctionBody) {
if (child1 is AbstractArendBlock && child2 is AbstractArendBlock && shouldWrapLetExpression(child1.node.elementType, child2.node.psi)) return oneCrlf
if (child1 is AbstractArendBlock && child1.node.elementType == FAT_ARROW) return oneSpaceWrap
if (needsCrlfInCoClausesBlock(child1, child2)) return oneCrlf
return super.getSpacing(child1, child2)
}
if (nodePsi is ArendNewExpr && needsCrlfInCoClausesBlock(child1, child2)) {
val whitespace = nodePsi.lbrace?.nextSibling as? PsiWhiteSpace
return if (whitespace != null && !whitespace.textContains('\n')) oneSpaceWrap else oneCrlf
}
if (nodePsi is ArendLocalCoClause && needsCrlfInCoClausesBlock(child1, child2)) return oneCrlf
if (nodePsi is ArendDefFunction) {
if (child2 is AbstractArendBlock && child2.node.elementType == FUNCTION_BODY) {
val child1node = (child1 as? AbstractArendBlock)?.node
val child2node = (child2 as? AbstractArendBlock)?.node?.psi as? ArendFunctionBody
if (child1node != null && child2node != null &&
!AREND_COMMENTS.contains(child1node.elementType) && child2node.fatArrow != null) return oneSpaceNoWrap
} else if (child1 is AbstractArendBlock && child2 is AbstractArendBlock) {
val child1et = child1.node.elementType
val child2psi = child2.node.psi
if (child1et == COLON && child2psi is ArendExpr) return oneSpaceWrap
}
}
if (child1 is AbstractBlock && child2 is AbstractBlock) {
val psi1 = child1.node.psi
val psi2 = child2.node.psi
val c1et = child1.node.elementType
val c2et = child2.node.elementType
val c1comment = child1 is DocCommentBlock
if ((AREND_COMMENTS.contains(c1et) || c1comment) && (psi2 is ArendStat || psi2 is ArendClassStat))
return (if ((c1et == DOC_COMMENT || c1comment) && (psi2 is ArendStat && psi2.statCmd == null)) oneCrlf else oneBlankLine)
else if ((psi1 is ArendStat || psi1 is ArendClassStat) && (TokenSet.create(BLOCK_COMMENT, DOC_COMMENT, DOC_TEXT).contains(c2et) || child2 is DocCommentBlock)) return oneBlankLine
if (nodePsi is ArendWithBody && (c1et == LBRACE || c2et == RBRACE)) return oneCrlf
if (nodePsi is ArendCaseExpr) when {
(c1et == CASE_ARG && c2et == WITH_BODY) -> return oneSpaceWrap
(c1et == CASE_ARG && c2et == COMMA) -> return noWhitespace
(c1et == COMMA && c2et == CASE_ARG) -> return oneSpaceWrap
(c1et == CASE_ARG && c2et == RETURN_KW) -> return oneSpaceWrap
(c1et == RETURN_KW && c2et == RETURN_EXPR) -> return oneSpaceNoWrap
(c1et == RETURN_EXPR && c2et == WITH_BODY) -> return oneSpaceWrap
}
if (nodePsi is ArendCaseArg) {
if ((c1et == EXPR || c1et == DEF_IDENTIFIER) && c2et == COLON) return oneSpaceWrap
if (c1et == COLON && psi2 is ArendExpr) return oneSpaceWrap
}
if ((nodePsi is ArendNameTele || nodePsi is ArendTypedExpr) && (c1et == IDENTIFIER_OR_UNKNOWN && c2et == COLON)) return oneSpaceWrap
if (c1et == NAME_TELE && c2et == NAME_TELE ||
c1et == TYPE_TELE && c2et == TYPE_TELE ||
c1et == FIELD_TELE && c2et == FIELD_TELE ||
c1et == LAM_TELE && c2et == LAM_TELE) return oneSpaceWrap
if (nodePsi is ArendNewExpr) {
when {
c1et == ARGUMENT_APP_EXPR && c2et == WITH_BODY -> return oneSpaceWrap
c1et == c2et && c2et == LOCAL_CO_CLAUSE -> return oneSpaceWrap
}
}
if (shouldWrapLetExpression(c1et, psi2)) return oneCrlf
if (nodePsi is ArendClause && (c1et == FAT_ARROW || c2et == FAT_ARROW || c1et == COMMA && c2et == PATTERN)) return oneSpaceWrap
if (nodePsi is ArendCoClauseDef && (psi1 is ArendNameTele || psi1 is ArendReturnExpr) && (psi2 as? ArendFunctionBody)?.kind == ArendFunctionBody.Kind.COCLAUSE) return oneSpaceWrap
if (nodePsi is ArendPattern && (c1et == DEF_IDENTIFIER || c1et == PATTERN) && c2et == PATTERN) return oneSpaceWrap
if ((nodePsi is ArendNameTele || nodePsi is ArendTypeTele || nodePsi is ArendFieldTele) && (c1et == LBRACE || c2et == RBRACE || c1et == LPAREN || c2et == RPAREN)) return noWhitespace
if ((nodePsi is ArendDefinition<*> || nodePsi is ArendClassStat) && (psi2 is ArendPrec || psi2 is ArendDefIdentifier)) return oneSpaceNoWrap
if (nodePsi is ArendPrec && (c1et in listOf(INFIX_LEFT_KW, INFIX_NON_KW, INFIX_RIGHT_KW) && c2et == NUMBER)) return oneSpaceNoWrap
if (nodePsi is ArendDefClass) when {
c1et == LBRACE && c2et == RBRACE -> return noWhitespace
c1et == LBRACE && c2et == CLASS_STAT -> return oneCrlf
c1et == CLASS_STAT && c2et == RBRACE -> return oneCrlf
c1et == CLASS_STAT && c2et == CLASS_STAT -> if (psi1 is ArendClassStat && psi2 is ArendClassStat) when {
(psi1.definition != null) || (psi2.definition != null) -> return oneBlankLine
}
}
return if (psi1 is ArendStat && psi2 is ArendStat) {
if (psi1.statCmd == null || psi2.statCmd == null) oneBlankLine else oneCrlf /* Delimiting blank line between proper statements */
} else if (psi1 is ArendStat && c2et == RBRACE ||
c1et == LBRACE && (psi2 is ArendStat || child2 is DocCommentBlock || c2et == DOC_COMMENT)) oneCrlf
else if ((nodePsi is ArendNsUsing || nodePsi is ArendStatCmd)) { /* Spacing rules for hiding/using refs in namespace commands */
when {
(c1et == LPAREN && (c2et == REF_IDENTIFIER || c2et == NS_ID || c2et == RPAREN)) ||
((c1et == REF_IDENTIFIER || c1et == NS_ID) && (c2et == COMMA || c2et == RPAREN)) -> noWhitespace
c1et == COMMA ||
(c1et == LONG_NAME && c2et == NS_USING) ||
((c1et == LONG_NAME || c1et == NS_USING) && c2et == HIDING_KW) ||
((c1et == HIDING_KW || c1et == USING_KW) && c2et == LPAREN) -> oneSpaceWrap
else -> null
}
} else if (nodePsi is ArendNsId && ((c1et == REF_IDENTIFIER && c2et == AS_KW) || (c1et == AS_KW && c2et == DEF_IDENTIFIER))) oneSpaceWrap
else null
}
return null
}