Add a whitespace PsiElement after a bracket

Hi,

I have a PHP array like this:

return [
'invokables' => [

],
];

The [] is a ArrayCreationExpression PSI.

I want to add a key inside and it's works

if (psiElement is ArrayCreationExpression) {
val arrayKey = psiElement.addAfter(PhpPsiElementFactory.createFromText(project, ClassConstantReference::class.java,"$namespace::class")!!, psiElement.firstChild)
if (!invokableFactory) {
arrayKey.add(PhpPsiElementFactory.createFromText(project, LeafPsiElement::class.java, "=>")!!)
arrayKey.add(PhpPsiElementFactory.createFromText(project, ClassConstantReference::class.java, namespace + "Factory::class")!!)
}
arrayKey.add(comma)

}


The output is:

return [
'invokables' => [Something\Here\And\Foo::class

],
];

I read we don't need to add whitespace because the API does that for us but it's not working and when I try to add a whitespace with the text "\n" it's not working either.

How to add a new line after the open bracket?

 

0
1 comment

If there is a corresponding setting in Code Style for PHP, it should work

0

Please sign in to leave a comment.