From 64b4c2d49b9b976b4b96325917c264f832e79da0 Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Wed, 19 Mar 2014 09:15:54 +0400 Subject: [PATCH] Fix scripting formatter to avoid extra indent in invisible block node. --- .../src/org/jetbrains/jet/plugin/formatter/JetBlock.java | 9 ++++++++- idea/testData/formatter/Script.after.kts | 9 +++++++++ idea/testData/formatter/Script.kts | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 idea/testData/formatter/Script.after.kts create mode 100644 idea/testData/formatter/Script.kts diff --git a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java index e2f19e414d8..fc96eed1076 100644 --- a/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java +++ b/idea/src/org/jetbrains/jet/plugin/formatter/JetBlock.java @@ -267,7 +267,7 @@ public class JetBlock extends AbstractBlock { .forType(PROPERTY_ACCESSOR) .set(Indent.getNormalIndent()), - ASTIndentStrategy.forNode("For a single statement if 'for'") + ASTIndentStrategy.forNode("For a single statement in 'for'") .in(BODY) .notForType(BLOCK) .set(Indent.getNormalIndent()), @@ -302,6 +302,13 @@ public class JetBlock extends AbstractBlock { ASTNode childParent = child.getTreeParent(); IElementType childType = child.getElementType(); + // SCRIPT: Avoid indenting script top BLOCK contents + if (childParent != null && childParent.getTreeParent() != null) { + if (childParent.getElementType() == BLOCK && childParent.getTreeParent().getElementType() == SCRIPT) { + return Indent.getNoneIndent(); + } + } + for (ASTIndentStrategy strategy : INDENT_RULES) { Indent indent = strategy.getIndent(child); if (indent != null) { diff --git a/idea/testData/formatter/Script.after.kts b/idea/testData/formatter/Script.after.kts new file mode 100644 index 00000000000..0d419be39e8 --- /dev/null +++ b/idea/testData/formatter/Script.after.kts @@ -0,0 +1,9 @@ +import a.b.c + +val x = 0 +fun fn() { + println(x) +} + +var y = fn() +y = y + 1 diff --git a/idea/testData/formatter/Script.kts b/idea/testData/formatter/Script.kts new file mode 100644 index 00000000000..8b6c78b5738 --- /dev/null +++ b/idea/testData/formatter/Script.kts @@ -0,0 +1,8 @@ +import a.b.c +val x = 0 + fun fn() { + println(x) +} + + var y = fn() + y = y+1