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
Please sign in to leave a comment.
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.
In PSI Viewer i found that this PsiElement(SMARTY_FRAGMENT)
But for some reason I can’t get PsiElement {'tpl' | chunk} in getReferencesByElement
Hi,
Note that this is a template language and it has two PSI roots:
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).
I tried to get STRING_LITERAL like this
but the getReferencesByElement call never got called. I can't access any psiElement Smarty.
It seems that you cannot contribute references to Smarty elements because of:
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?
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.