XmlPatterns.xmlText pattern won't work when registering PsiReferenceProvider

public class MyReferenceContributor extends PsiReferenceContributor {     @Override     public void registerReferenceProviders(PsiReferenceRegistrar registrar) {         registrar.registerReferenceProvider(XmlPatterns.xmlText(), new PsiReferenceProvider() {             @NotNull             @Override             public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {                 return new PsiReference[]{new MyXmlTextReference((XmlText) element)};             }         });     } }

Here getReferencesByElement is not invoked at all. I see that I do have XmlTextImpl element is present in my psi tree, and see that my XmlPatterns.xmlAttributeValue() providers work as expected. But not for XmlPatterns.xmlText(). Why?


And no, I did not forget to register this extension in plugin.xml. My actual registerReferenceProviders registers some other providers that work.


This is because for some historical reasons, references for XML text inside tags should be registered for XmlTag elements, not the text ones. And better with the tag name given. Sorry for the confusion. So please try registering them via XmlPatterns.xmlTag().withLocalName(...).withNamespace(...)


Works like a charm using XmlTag.getValue().getTrimmedText(), thanks!


Please sign in to leave a comment.