ReferenceContributor not work from custom langauge

I’m developing a custom language plugin.
The language support @xxxx to refer to xxxx argument in corresponding Golang method.

I follow the Simple language plugin and develop my MyReferenceContributor and register it in the plugin.xml.

<psi.referenceContributor language="MyLanguage" "xxxxx.MyReferenceContributor"  />

But it seems that MyReferenceContributor is NEVER called via LOG / DEBUG.

Is there anything special for ReferenceContributor when it is from custom language?

Hi.

I’ve spent much time to understand how to do it in my own custom languages and why it didn’t work :grin:

Things that help me to inject references to my psi elements:

  1. add override fun getReferences(): Array<PsiReference> = ReferenceProvidersRegistry.getReferencesFromProviders(this) to the element should have references
  2. add { implements=["com.intellij.psi.NavigatablePsiElement"] } into the bnf to the according psi element pattern declaration

Do not forget to rebuild parser.
Also I’ve noticed that your snippet has error, there are no “implementation” attribute, so correct version will be: <psi.referenceContributor language="MyLanguage" implementation="xxxxx.MyReferenceContributor" />

2 Likes

Languages must explicitly enable references in places where they expect contributed references. It cannot be done automatically since has performance and correctness consequences.

Thanks guy. After implementing getReferences to my language element. The reference and completion works.