Indentation after pressing enter


I have a formatting issue with my custom language plugin that i'm not sure how to resolve.

After formatting the file, if I click between the braces it shows the caret at the correct location:

However, if i place my caret on the top brace and press enter, the caret doesn't indent properly

I'm guessing this is something to do with the Alignment setting, i've tried creating a new alignment for all of the children of the statement block, but this doesn't seem to affect the caret.

Does anyone have any suggestions on how to investigate/fix this?

1 comment
Comment actions Permalink

The solution was to implement getChildAttributes like so:

public ChildAttributes getChildAttributes(final int newIndex)
final LSLBlock previousBlock = newIndex == 0 ? null : getSubLSLBlocks().get(newIndex - 1);
final IElementType previousType = previousBlock == null ? null : previousBlock.getNode().getElementType();

if (previousBlock == null)
return new ChildAttributes(Indent.getNoneIndent(), null);

if (previousType == LSLTypes.BRACES_START || previousType == LSLTypes.BRACKETS_START)
// Indentation after first brace
return new ChildAttributes(Indent.getNormalIndent(), null);

if (!previousBlock.isIncomplete() && newIndex < getSubLSLBlocks().size() && previousType != TokenType.ERROR_ELEMENT)
// Indentation before last brace
return new ChildAttributes(previousBlock.getIndent(), previousBlock.getAlignment());

return new ChildAttributes(previousBlock.getIndent(), previousBlock.getAlignment());

Please sign in to leave a comment.