Is there any way to declare a reference contributor for PSI element that not called getReferencesFromProviders fromPsiElement.getReferences()
Hi, dear support team!
I have trouble with registering the reference contributor.
I wanna add a reference contributor for GraphQL language PSI element ( com.intellij.lang.jsgraphql.psi.GraphQLQuotedString).
A fragmet of a GraphQL file:
```
@resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Products") @doc(description: "The products query searches for products that match the criteria specified in the search and filter attributes.") @cache(cacheIdentity: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product\\Identity")
category (
```
The certain task is to add references to PHP classes used within quoted strings.
The PSI element does not call com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry#getReferencesFromProviders(PsiElement)} from the implementation of PsiElement.getReferences().
What the best solution to declare a contributor.
Thank you!
请先登录再写评论。
You can find the information regarding the Reference Contributor in our docs:
https://www.jetbrains.org/intellij/sdk/docs/tutorials/custom_language_support/reference_contributor.html
Hi Jakub!
The mentioned document is related to custom language support.
The issue is that GraphQL language is not custom, it is being implemented under Intellij namespace ('com.intellij.lang.jsgraphql').
Therefore I have no control under PSI elements implementation of that language.
As a result, I can't declare a Reference Contributor in the way described in the mentioned document.
I believe there must be some hook or extension point to do that.
Reimplementing the whole language just to cover this case would be the worst scenario.
However, Thank you for your reply.
First of all, I'd suggest you look at the Plugin Dependencies docs.
In your plugin's Gradle configuration you can set a dependency on another plugin (+ in plugin.xml as well), so you'll be able to reuse its PSI related classes.
Having that, you can create a new psi.referenceContributor EP implementation for the PHP language using the GraphQL PSI classes for building some references.
Since the GraphQL plugin is a 3rd party one, you can review its source code on GitHub.
Thank you!
Regarding the dependencies.
My plugin already has a declared dependency on the GraphQL plugin.
Gradle build:
Creating a new psi.referenceContributor EP implementation for the PHP language using the GraphQL PSI classes for building some references works like a charm. No issue there.
However, I want to create a new psi.referenceContributor EP implementation for the GraphQL language using PHP PSI class references. Vice versa.
I've gone through the source code of the GraphQL plugin. The authors did not provide the possibility to get references by the needed PSI class.
For example com.jetbrains.php.lang.psi.elements.impl.StringLiteralExpressionImpl#getReferences:
Therefore registering psi.referenceContributor for literal expression of PHP works great.
Unlike PHP element com.intellij.lang.jsgraphql.psi.impl.GraphQLQuotedStringImpl doesn't overide the super getReferences() function. As result registering psi.referenceContributor doesn't make any effect.
Is there exist any extension point, hook, decorator, whatever to change the implementation of the GraphQL PSI element on my plugin side. Or I can achieve it by only modifying the source code of the GraphQL plugin?
In this case - if there is no getReferences implemented to use ReferenceProvidersRegistry - it wouldn't be possible.
Read JavaDocs for more information:
https://github.com/JetBrains/intellij-community/blob/master/platform/core-api/src/com/intellij/psi/PsiReferenceContributor.java
Hi Vitalii. I had quite a similar problem. Been able to solve it only using Java Instrumentation to patch binary code of needed PSI classes. You can find some working code here https://github.com/ArtsiomCh/CMake under ../plus/agent/Instrumentation* section.
PS FYI it's a bit hacky and dirty way, so be prepared... ;)