Registering reference providers for Twig tokens in PHPStorm

Hey,

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(
                TwigTokenTypes.STRING_TEXT)
                .afterSiblingSkipping(
                        PlatformPatterns.or(
                                PlatformPatterns.psiElement(TwigTokenTypes.SINGLE_QUOTE),
                                PlatformPatterns.psiElement(TwigTokenTypes.DOUBLE_QUOTE)),

                        PlatformPatterns.psiElement(TwigTokenTypes.LBRACE)
                        .afterSibling(
                                PlatformPatterns.psiElement(TwigTokenTypes.IDENTIFIER)
                                        .withText(StandardPatterns.string().equalTo("path"))
                        )

                );



Both do not match in any way.

3 comments
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 ...

0
Comment actions Permalink

PsiViewer plugin (http://plugins.intellij.net/plugin/?id=227) may be helpful to understand the PSI structure.

0
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...

0

Please sign in to leave a comment.