Add reference resololution to groovy language
Hallo,
I have a groovy dsl that looks like this:
ID_1 {
ID_2
ID_3
}
ID_2 {
...
}
ID_3 {
...
}
Of course the references in the method-call ID_1 cannot be resolved. So I tried to create a plugin with a ReferenceContributor:
<psi.referenceContributor language="Groovy" implementation="MyReferenceContributor"/>
registrar.registerReferenceProvider(PlatformPatterns.psiElement(GrReferenceExpression.class), new PsiReferenceProvider() { @NotNull @Override public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) { return new PsiReference[] {new MyReferenceBase(element, textRange)}; } }); }
the registerReferenceProvider-Method is never called. In former plugins I wrote I had to implement the getReference-Method of the ReferencePsiElement. Do you know how I can achieve additional reference resolution for existing languages, in my case Groovy. Thanks for any help
Please sign in to leave a comment.
Reference contributors can only be used to contribute references to elements which support that - those are normally string literals and similar elements, not identifiers.
To support reference resolution for a custom Groovy DSL, you need to use the GDSL framework: https://confluence.jetbrains.com/display/GRVY/Scripting+IDE+for+DSL+awareness
Thank you Dmitry,
I looked into the GDSL-Framework and it's great. However I would need a little help to find the right approach. I have many groovy scipts with a lot of lines. All in all I have about 20000 definitions like that:
When I use GDSL the contributor is executed at runtime for the current file. At this time I would already need access to all other definitions in the other files (GrMethodCallExpression-Psi). Would you recommend to index these PsiElements in a GDSL-script? Or should I write a plugin that creates stub indices? Can I access these stub indices in a GDSL script? Is there maybe a way to combine GDSL-Scripts with the groovy based LivePlugins? Would be great if you have a hint for the best procedure.