Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I attach a Reference Provider through LivePlugin? #146

Open
UnbridledGames opened this issue Sep 19, 2022 · 2 comments
Open

Can I attach a Reference Provider through LivePlugin? #146

UnbridledGames opened this issue Sep 19, 2022 · 2 comments

Comments

@UnbridledGames
Copy link

I am trying to extend my previous plugin (auto-completing certain text inside Yaml string values) and make it so that those are ctrl-clickable so that I can navigate to the matching yaml key value in whatever file they exist in.

Following some other examples I have written the code that SEEMS like it should work... however... every time I try to actually register the ReferenceContributor, I get this IDE error:

java.lang.Throwable: Reference provider registration is only allowed from PsiReferenceContributor

I have tried to do it a hundred ways, and always get this error. So it seems I'm not doing it correctly. And I AM running registrar.regidterReferenceProvider from inside a PsiReferenceContributor instance. So maybe it can only be registered internally upon plugin startup, defined in the gradle config?

Does LivePlugin have any functionality to attach/register a ReferenceContributor in the proper way? I'm at a loss, and spent the last 48 hours tearing my hair out trying to get an actual plugin to even remotely work.

@dkandalov
Copy link
Owner

Sorry for the slow reply. I don't really know the answer and was trying to focus on a conference talk 🙈

Searching IJ code for "Reference provider registration is only allowed from PsiReferenceContributor" there is only one usage of it in com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl#registerReferenceProvider() and it has this condition myInitialized && !ApplicationManager.getApplication().isUnitTestMode() && parentDisposable == null. It also looks like this is just logging the error but runs the code anyway.

There might be a good reasons it logs an error, so why not try using PsiReferenceContributor and register it via extension point com.intellij.psi.PsiReferenceContributor#EP_NAME? It's not guaranteed that it will work though because some IJ APIs are not designed to be very reloadable.

@dkandalov
Copy link
Owner

dkandalov commented Oct 14, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants