phpphpstormsyntax-highlighting

How to auto inject language by place pattern in PhpStorm for function?


How to configure PhpStorm to automatically inject Bash inside run(...) function call? For example i want to inject bash here:

run("mv source dest && echo 'bash';");

This does not working:

+ phpLiteralExpression().withText("run")

Solution

  • Try the following places pattern:

    + phpLiteralExpression().withSuperParent(2, phpFunctionReference().withText(string().startsWith("run(")))
    

    Unfortunately there is no documentation for this feature, in fact the docs specifically warn:

    These rules are PhpStorm internals, and it is strongly recommended that you use the predefined injection configurations and avoid creating new ones.

    So it is in practise necessary to look at the sources of IntelliJ IDEA. The classes of interest are com.intellij.patterns.PlatformPatterns and com.intellij.patterns.PsiElementPattern and their various superclasses.