fix: Better indenting logic
This commit is contained in:
parent
6cc6a00aeb
commit
a266ff94c3
1 changed files with 18 additions and 6 deletions
|
@ -26,12 +26,18 @@ import com.intellij.formatting.Wrap;
|
||||||
import com.intellij.lang.ASTNode;
|
import com.intellij.lang.ASTNode;
|
||||||
import com.intellij.psi.TokenType;
|
import com.intellij.psi.TokenType;
|
||||||
import com.intellij.psi.formatter.common.AbstractBlock;
|
import com.intellij.psi.formatter.common.AbstractBlock;
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
|
import lombok.val;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.BLOCK;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.EXPR_LIST;
|
||||||
|
import static com.falsepattern.zigbrains.zig.psi.ZigTypes.INIT_LIST;
|
||||||
|
|
||||||
public class ZigBlock extends AbstractBlock {
|
public class ZigBlock extends AbstractBlock {
|
||||||
|
|
||||||
private final SpacingBuilder spacingBuilder;
|
private final SpacingBuilder spacingBuilder;
|
||||||
|
@ -69,16 +75,22 @@ public class ZigBlock extends AbstractBlock {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @Nullable Indent getChildIndent() {
|
protected @Nullable Indent getChildIndent() {
|
||||||
if (myNode.getElementType() == ZigTypes.BLOCK) {
|
return getIndentBasedOnParentType(getNode().getElementType());
|
||||||
return Indent.getNormalIndent();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Indent.getNoneIndent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Indent getIndent() {
|
public Indent getIndent() {
|
||||||
if (myNode.getElementType() == ZigTypes.STATEMENT) {
|
val parent = getNode().getTreeParent();
|
||||||
|
if (parent != null) {
|
||||||
|
return getIndentBasedOnParentType(parent.getElementType());
|
||||||
|
}
|
||||||
|
return Indent.getNoneIndent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Indent getIndentBasedOnParentType(IElementType elementType) {
|
||||||
|
if (elementType == BLOCK ||
|
||||||
|
elementType == INIT_LIST ||
|
||||||
|
elementType == EXPR_LIST) {
|
||||||
return Indent.getNormalIndent();
|
return Indent.getNormalIndent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue