PsiReferenceContributor not triggered for certain element (GherkinTableCellImpl)

Answered

I have the following code for PSI classes from the bundled plugin cucumber-java:

```

@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(GherkinStep.class),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext context) {
GherkinStep step = (GherkinStep) element;
final String text = step.getText();
if (text == null || !text.contains("$")) {
return PsiReference.EMPTY_ARRAY;
}
return createVariableReferences(element, text);
}
});

registrar.registerReferenceProvider(PlatformPatterns.psiElement(GherkinTableCell.class),
new PsiReferenceProvider() {
@NotNull
@Override
public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element,
@NotNull ProcessingContext context) {
GherkinTableCell cell = (GherkinTableCell) element;
final String text = cell.getText();
if (text == null || !text.contains("$")) {
return PsiReference.EMPTY_ARRAY;
}
return createVariableReferences(element, text);
}
}, PsiReferenceRegistrar.HIGHER_PRIORITY * 10);

}

The PsiReferenceProvider for GherkinStep is triggered, the one for GherkinTableCell is not. I have checked the PSI tree of the file opened in the editor and there is a GherkinTableCellImpl there. Even clicking and changing it doesn't do anything.

I can't see any reason why it would work with one GherkinPsiElement but not the other. I added the priority as a test but it doesn't change anything.

Thanks!

1
4 comments

Hello, Simon!

 

I've just checked the problem. Unfortunately  `GherkinTableCell` class didn't support references extension. I've just changed it, now it can.

The fix will be available with the next EAP of IDEA. If you want, I could build a custom cucumber-java plugin with the fix.

0

Andrey Vokin

That's awesome, thank you! A fix in the next EAP is totally fine. I know my code generally works, I can wait a bit.

0

Andrey Vokin Can confirm it's working with the latest EAP, thanks.

0

Please sign in to leave a comment.