Add entries in goto declaration or usages
Hi,
I have a custom web service tooling. An IDL is written in Java to define beans and services, and used to generate beans and client proxies in multiple languages.
In JavaScript for exemple, currently when I run “goto declaration or usage” on a generated client proxy method, it goes to generated code of the class as expected. I would like to add a new entry, and IDE to open the menu asking which point to go between native JS class or IDL java class, like it does when running it on a method and you choose which usage to go.
I know how to find PsiElements where to go, but is there a way to inject alternative declarations so the IDE ask user where to go on “Ctrl + click” ?
I currently did it implementing an Action with a new menu entry in “Go to” menu, but I would like it a bit more integrated as we usually don't care navigating to generated code.
Please sign in to leave a comment.
Hi Julien,
You can contribute references to elements from other languages with
com.intellij.psi.PsiReferenceContributor
. But there is a catch - element for which you would like to contribute references must implementcom.intellij.psi.ContributedReferenceHost
.You can use the PSI viewer to find out which element you want to contribute references to: https://plugins.jetbrains.com/docs/intellij/explore-api.html#internalMode
Then, check if it implements
com.intellij.psi.ContributedReferenceHost
. If it does, then implement a contributor that will provide references that resolve to additional elements.From what I understand, nothing in JavaScript or in Java implements com.intellij.psi.ContributedReferenceHost ? It would mean there is not way achieve that goal in JavaScript and Java using PsiReferenceContributor ?
With following test, I'm able to have Ctrl+Click on a JavaScript constructor that navigate to expected Java class definition. But it breaks JS import features and I guess many other things. I would like to add a new alternative goto after the native one, not to replace the native one. Is there a way to fix it ?