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?

3 comments

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

0

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(...)

0

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

0

Please sign in to leave a comment.