PsiReferenceContributor is not working
已回答
When attempting to use the "Go to Declaration" feature, the expected behavior of navigating to the declaration of a variable or function is not occurring as intended. Th Config Object contains the PsiElement and the PsiFile where the Element is declared but somehwo if a hold Strg and get over the text. i get the message “Can not find Declaration to go to”.
Can someone maybe help me with this?
This is my code:
public class ConfigReferenceContributor extends PsiReferenceContributor {
@Override
public void registerReferenceProviders(@NotNull PsiReferenceRegistrar registrar) {
registrar.registerReferenceProvider(PlatformPatterns.psiElement(PsiElement.class), new ConfigReferenceProvider());
}
}
public class ConfigReference extends PsiReferenceBase<PsiElement> {
private final Config config;
ConfigReference(Config config) {
super(config.getElement(), config.getElement().getTextRange());
this.config = config;
}
@Override
public @Nullable PsiElement resolve() {
return config.getElement();
}
}
public class ConfigReferenceProvider extends PsiReferenceProvider {
@Override
public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
List<PsiReference> psiReferences = new ArrayList<>();
if (element instanceof ParameterListImpl) {
PsiElement method = element.getParent();
if (method instanceof FunctionReferenceImpl function) {
PsiElement configKey = element.getFirstChild();
if (configKey != null) {
iterateOverConfigFiles(element.getProject()).stream()
.filter(config -> configKey.getText().replace("\"", "").equals(config.getKey()))
.findFirst().ifPresent(result -> psiReferences.add(new ConfigReference(result)));
}
}
}
System.out.println(Arrays.toString(psiReferences.toArray(new PsiReference[0])));
return psiReferences.toArray(new PsiReference[0]);
}
}
请先登录再写评论。
It is impossible to debug code from this information. Please see https://plugins.jetbrains.com/docs/intellij/element-patterns.html#tools-and-debugging and make sure that your references are actually installed on the correct element in the first place.
If you're still stuck, please link your full plugin's sources.
I have the same issue for some reasons my reference contributor is not working, none of the breakpoints is hit. I have registered it in the `plugin.xml` but still it not does seem to be recognized.
Example code:
bnf:
I know it's hard to debug with limited info, but should the
mixin
&implements
be applied to the function declaration or the functionCall in the grammar file (.bnf)? Or could that even impact the code contribution?Dinbtechit Please always create new threads for different problem. And please link your full sources.