From 5d156c2edb782ded2389dd7b9c1d8f2a1a2847d3 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Wed, 6 Mar 2019 22:26:31 +0300 Subject: [PATCH] Debugger: Fix indentation in code fragments --- .../idea/formatter/KotlinCommonBlock.kt | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt index cff11c0ae5d..3b50899f645 100644 --- a/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt +++ b/idea/formatter/src/org/jetbrains/kotlin/idea/formatter/KotlinCommonBlock.kt @@ -221,10 +221,8 @@ abstract class KotlinCommonBlock( val childParent = child.treeParent val childType = child.elementType - if (childParent?.treeParent != null) { - if (childParent.elementType === KtNodeTypes.BLOCK && childParent.treeParent.elementType === KtNodeTypes.SCRIPT) { - return Indent.getNoneIndent() - } + if (childParent != null && isInCodeChunk(childParent)) { + return Indent.getNoneIndent() } // do not indent child after heading comments inside declaration @@ -266,10 +264,24 @@ abstract class KotlinCommonBlock( return Indent.getNoneIndent() } + private fun isInCodeChunk(node: ASTNode): Boolean { + val parent = node.treeParent ?: return false + + if (node.elementType != KtNodeTypes.BLOCK) { + return false + } + + val parentType = parent.elementType + return parentType == KtNodeTypes.SCRIPT + || parentType == KtNodeTypes.BLOCK_CODE_FRAGMENT + || parentType == KtNodeTypes.EXPRESSION_CODE_FRAGMENT + || parentType == KtNodeTypes.TYPE_CODE_FRAGMENT + } + fun getChildAttributes(newChildIndex: Int): ChildAttributes { val type = node.elementType - if (node.elementType == KtNodeTypes.BLOCK && node.treeParent.elementType == KtNodeTypes.SCRIPT) { + if (isInCodeChunk(node)) { return ChildAttributes(Indent.getNoneIndent(), null) }