Registering reference providers for Twig tokens in PHPStorm


I try to register a reference provider for a TwigTokenTypes.STRING_TEXT, using the registrar in the contributor. Unfortunatly this leads not the call of the provider while ctrl+click or ctrl+hovering it.

I tried a simple matching condition:

PsiElementPattern.Capture<PsiElement> psiElementCapture = PlatformPatterns.psiElement(TwigTokenTypes.STRING_TEXT);

And I tried a more complex condition:

PsiElementPattern.Capture<PsiElement> psiElementCapture = PlatformPatterns.psiElement(



Both do not match in any way.

Comment actions Permalink

I've tracked it down to these facts:

  • The twig tokens are not fired for resolving
  • I cannot find anything to match PsiElement(TWIG_FRAGMENT), which I found by debugging every PsiElement emitted from CTRL+Hover
  • The PsiElement(TWIG_FRAGMENT) is enclosed by XML PsiElements (Which may be a hint for parsing...)

I'm clueless ...

Comment actions Permalink

PsiViewer plugin ( may be helpful to understand the PSI structure.

Comment actions Permalink

I used the PsiViewer to get the info I've already presented to you. But using the PsiElement(IDENTIFIER) from the viewer does not fire the event of the reference contributor.
Do it get it right, that PsiElement(IDENTIFIER) or Language:Twig refers to TwigTokenTypes.IDENTIFIER ? Maybe the problem is, that I use the wrong token class? I really don't know...


Please sign in to leave a comment.