Add a whitespace PsiElement after a bracket


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,,"$namespace::class")!!, psiElement.firstChild)
if (!invokableFactory) {
arrayKey.add(PhpPsiElementFactory.createFromText(project,, "=>")!!)
arrayKey.add(PhpPsiElementFactory.createFromText(project,, namespace + "Factory::class")!!)


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?


1 comment
Comment actions Permalink

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


Please sign in to leave a comment.