How to add a PsiReferenceContributor for an existing language?

I'm having trouble understanding the correct way to implement a reference provider. I'm not creating a custom language plugin, so a lot of possible solutions i found to my problem don't apply here. So far i have:

plugin.xml

<extensions defaultExtensionNs="com.intellij">
     <psi.referenceContributor language="PHP" implementation="my.plugin.MyReferenceContributor" />
</extensions>


MyReferenceContributor.java

public class MyReferenceContributor extends PsiReferenceContributor
{
    @Override
    public void registerReferenceProviders(PsiReferenceRegistrar registrar)
    {
        // this doesn't get executed at all
        registrar.registerReferenceProvider(PlatformPatterns.psiElement(PhpNamedElement.class), new MyReferenceProvider());
    }
}



MyReferenceProvider.java

public class MyReferenceProvider extends PsiReferenceProvider
{
    @NotNull
    @Override
    public PsiReference[] getReferencesByElement(@NotNull final PsiElement element, @NotNull final ProcessingContext context)
    {
        // this doesn't execute
        System.out.println(((PhpNamedElement) element).getName());

        return new PsiReference[0];
    }
}


Is this the correct way to do this? Why isn't my provider registered?

3 comments
Comment actions Permalink

Did You try to register your contributor without language attribute?
BTW - remember, language ID is case sensitive.

0
Comment actions Permalink

You can take a look at working PHP reference contributor example in the sources of a very popular Symfony http://plugins.jetbrains.com/plugin/7219?pr=phpStorm

0
Comment actions Permalink

Hello, Danijel Fabijan!

Did you find the answer?

I've similar problem here:

import com.jetbrains.php.lang.psi.elements.impl.ClassReferenceImpl

class FactoryAndProxyReferenceContributor : PsiReferenceContributor() {

override fun registerReferenceProviders(registrar: PsiReferenceRegistrar) {
registrar.registerReferenceProvider(
PlatformPatterns.psiElement(ClassReferenceImpl::class.java),
FactoryAndProxyReferenceProvider()
)
}
}

This should work, technically, but it is not...

I would be very grateful for your answer.

Regards,

0

Please sign in to leave a comment.