Indenter: fix indentation on top level in scripts
This commit is contained in:
@@ -151,6 +151,11 @@ abstract class KotlinCommonBlock(
|
||||
|
||||
fun getChildAttributes(newChildIndex: Int): ChildAttributes {
|
||||
val type = node.elementType
|
||||
|
||||
if (node.elementType == KtNodeTypes.BLOCK && node.treeParent.elementType == KtNodeTypes.SCRIPT) {
|
||||
return ChildAttributes(Indent.getNoneIndent(), null)
|
||||
}
|
||||
|
||||
return when (type) {
|
||||
in CODE_BLOCKS, KtNodeTypes.WHEN, KtNodeTypes.IF, KtNodeTypes.FOR, KtNodeTypes.WHILE, KtNodeTypes.DO_WHILE -> ChildAttributes(Indent.getNormalIndent(), null)
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
foo() {
|
||||
|
||||
}
|
||||
<caret>
|
||||
|
||||
val c = 4
|
||||
@@ -0,0 +1,5 @@
|
||||
foo() {
|
||||
|
||||
}<caret>
|
||||
|
||||
val c = 4
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
|
||||
foo()
|
||||
<caret>
|
||||
|
||||
foo()
|
||||
@@ -0,0 +1,7 @@
|
||||
fun foo() {
|
||||
|
||||
}
|
||||
|
||||
foo()<caret>
|
||||
|
||||
foo()
|
||||
@@ -303,6 +303,12 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/indentationOnNewline/script"), Pattern.compile("^([^\\.]+)\\.after\\.kt.*$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("ScriptAfterClosingBrace.after.kts")
|
||||
public void testScriptAfterClosingBrace() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/script/ScriptAfterClosingBrace.after.kts");
|
||||
doNewlineTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ScriptAfterExpression.after.kts")
|
||||
public void testScriptAfterExpression() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/script/ScriptAfterExpression.after.kts");
|
||||
@@ -321,6 +327,12 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio
|
||||
doNewlineTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ScriptBetweenFunctionCalls.after.kts")
|
||||
public void testScriptBetweenFunctionCalls() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/script/ScriptBetweenFunctionCalls.after.kts");
|
||||
doNewlineTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("ScriptInsideFun.after.kts")
|
||||
public void testScriptInsideFun() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/script/ScriptInsideFun.after.kts");
|
||||
|
||||
Reference in New Issue
Block a user