Creating reference contributors for Gherkin language elements



I'm trying to create Gherkin reference contributors for project specific things, however I'm having trouble with them.


I noticed that registered PsiReferenceProviders seem to work only for GherkinSteps, when registered e.g. as 

registrar.registerReferenceProvider(PlatformPatterns.psiElement(GherkinStep.class), new PsiReferenceProvider() {...});

However when I try to catch elements other than steps, e.g. GherkinScenarios or GherkinTags:

registrar.registerReferenceProvider(PlatformPatterns.psiElement(GherkinTag.class), new PsiReferenceProvider() {...});

nothing happens.

I debug my code as well, matching PsiElement.class as the pattern, but it was still only GherkinSteps PsiReferenceProvider#getReferencesByElement was executed for.

I haven't managed to find out if this works this way intentionally or not, but based on the current behaviour I don't seem to be able to add any reference to GherkinTags.



A different problem is that I would like to extend the set of references for a GherkinStep that is coming from the Gherkin plugin (org.jetbrains.plugins.cucumber.steps.reference.CucumberStepReference), with my own custom reference.

So, the Gherkin plugin adds this reference to steps to navigate to the step definition methods on Java side. However, I would like to add a reference to only certain steps, and only to a certain of those steps, specifically a path parameter, so that users could navigate to different files based on that path value.

After I add my contributor and reference, it seems that the only reference that is available is the one from the Gherkin plugin but not mine.

Is there a way to add my reference contributor while also keeping any other registered elsewhere?


Any help would be appreciated.

Comment actions Permalink

Hi Tamás,

1) To retrieve references from contributors PsiElement should return


 in method #getReferences. I've updated class GherkinTagImpl and pushed the change. 

2) Looks like this behaviour defined by com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference#COMPARATOR. If there are several references it'll take the one with shortest range.

Comment actions Permalink

Thank you Andrey,

I will look into them.


Please sign in to leave a comment.