Registering reference providers for SMARTY_FRAGMENT

Answered

HI. I need to register reference provider for SMARTY_FRAGMENT  but I can’t find where SMARTY_FRAGMENT is defined

0
7 comments

Hi,

I'm not sure I understand the question. The element type with debug name “SMARTY_FRAGMENT” is com.jetbrains.smarty.lang.SmartyElementTypes#OUTER_ELEMENT_TYPE.

If it doesn't answer your question, please provide all the details about the use case.

0

In PSI Viewer i found that this PsiElement(SMARTY_FRAGMENT) 

But for some reason I can’t get PsiElement {'tpl' | chunk} in getReferencesByElement

registrar.registerReferenceProvider(PlatformPatterns.psiElement(),
        new PsiReferenceProvider() {
            @Override
            public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
                LOG.info("text="+ element.getText());
                return PsiReference.EMPTY_ARRAY;
            }
        });
0

Hi,

Note that this is a template language and it has two PSI roots:

  1. SmartFile:Dummy.tpl - which is SmartyLanguage
  2. HtmlFile:Dummy.tpl - which is HTMLLanguage

SMARTY_FRAGMENT is just a dummy element in HTML PSI that is not parsed by HTML, but SmartyLanguage parser.

Similarly, you have SMARTY_TEMPLATE_HTML_TEXT element in Smarty PSI, which is left for parsing by HTMLLanguage parser.

I don't know what you are trying to provide references for, but I guess it is an element in Smarty language. In this case, you have to register a reference contributor for Smarty language and provide references for its elements (STRING_LITERAL? MODIFIER? IDENTIFIER in MODIFIER?).

Remember that references can be contributed to an element only if its PsiElement.getReferences() calls getting references from providers (see com.intellij.psi.PsiReferenceProvider's Javadoc).

0

 I tried to get STRING_LITERAL like this 

registrar.registerReferenceProvider(PlatformPatterns
                     .psiElement(SmartyTokenTypes.STRING_LITERAL)
                     .withParent(PlatformPatterns.psiElement(SmartyCompositeElementTypes.TAG)
                     ),
            new PsiReferenceProvider() {
                @Override
                public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
                    LOG.info("text="+ element.getText());
                    return PsiReference.EMPTY_ARRAY;
                }
            });
}

 

but the getReferencesByElement call never got called. I can't access any psiElement Smarty.

0

It seems that you cannot contribute references to Smarty elements because of:

Remember that references can be contributed to an element only if its PsiElement.getReferences() calls getting references from providers (see com.intellij.psi.PsiReferenceProvider's Javadoc).

0

Note that, if you're implementing a custom language, it won't by default support references registered through PsiReferenceContributor. If you want to support that, you need to call com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry.getReferencesFromProviders(PsiElement) from your implementation of PsiElement.getReferences().

 

Did I understand correctly that getReferencesByElement is not called for the PsiElement of a smarty template since in the smarty language getReferences() is not called for its PsiElement? 

Then what should I do?

0

Elements which allow to contribute reference from external plugins must call ReferenceProvidersRegistry.getReferencesFromProviders(). I don't see any Smarty element doing it, so your providers won't be called.

It seems not possible to contribute references to Smarty elements. Please explain your use case in detail. What reference do you want to contribute? Maybe there is another extension point for implementing the goal. If not, you can create an issue on the PhpStorm YouTrack: https://youtrack.jetbrains.com/issues/WI. Choose Subsystem “PHP Templates” with the request of adding the possibility of contributing references to some elements.

1

Please sign in to leave a comment.