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 {
|
fun getChildAttributes(newChildIndex: Int): ChildAttributes {
|
||||||
val type = node.elementType
|
val type = node.elementType
|
||||||
|
|
||||||
|
if (node.elementType == KtNodeTypes.BLOCK && node.treeParent.elementType == KtNodeTypes.SCRIPT) {
|
||||||
|
return ChildAttributes(Indent.getNoneIndent(), null)
|
||||||
|
}
|
||||||
|
|
||||||
return when (type) {
|
return when (type) {
|
||||||
in CODE_BLOCKS, KtNodeTypes.WHEN, KtNodeTypes.IF, KtNodeTypes.FOR, KtNodeTypes.WHILE, KtNodeTypes.DO_WHILE -> ChildAttributes(Indent.getNormalIndent(), null)
|
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);
|
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")
|
@TestMetadata("ScriptAfterExpression.after.kts")
|
||||||
public void testScriptAfterExpression() throws Exception {
|
public void testScriptAfterExpression() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/script/ScriptAfterExpression.after.kts");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/script/ScriptAfterExpression.after.kts");
|
||||||
@@ -321,6 +327,12 @@ public class TypingIndentationTestBaseGenerated extends AbstractTypingIndentatio
|
|||||||
doNewlineTest(fileName);
|
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")
|
@TestMetadata("ScriptInsideFun.after.kts")
|
||||||
public void testScriptInsideFun() throws Exception {
|
public void testScriptInsideFun() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/script/ScriptInsideFun.after.kts");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/indentationOnNewline/script/ScriptInsideFun.after.kts");
|
||||||
|
|||||||
Reference in New Issue
Block a user