PsiFileReference for custom java literal
Answered
I need to open custom file from specified folder after "go to declaration" on java String. I've created PsiReferenceContributor, which registers array of PsiReference (which return single PsiFile as getVariants(), resolve(), etc.), but I still get "cannot find declaration to go" message. There are no examples in documentation related with opening files from "go to".
Please sign in to leave a comment.
Please show your code
Why does your PsiFileImpl try to return references?
QueryReferenceContributor looks like good approach, but simply use FileReferenceSet there and return all references instead of "Stream.of..." expression
ok, I return single FileReference with FileReferenceSet, but still "cannot find declaration to go"
You must return com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet#getAllReferences, remove everything with Stream.... around it
Still isn't working
2nd parameter in FileReferenceSet must be the PsiElement for which references are provided, not the files[0] . Please look at existing usages of FileReferenceSet in IntelliJ Community sources for further details on customizing
So how FileReferenceSet has to know what files to open? There are no constructor parameters for this. "String str"? No. "PsiReferenceProvider provider"? Well, you told me not to create FileReferences manually.
It will resolve to all files which match the limitations set in FileReferenceSet - it can be customized to some degree. if you want to hardcode resolve target to specific file, you can simply return com.intellij.psi.PsiReferenceBase.Immediate and pass file in "resolveTo" parameter
It returns one FileReference, but it just ignored somewhere else
And even when it finds file by name - same situation.
Sorry I don't understand what the exact problem is. Please post/link updated code of what you're trying now
FileReferenceSet returns single FileReference which provides to file with name from "value", but IDE still shows message "cannot find declaration to go". Why?
passing '0' as "startinElement" is most probably wrong (at least for Java String literal). Try passing in com.intellij.psi.ElementManipulators#getOffsetInElement for given literalExpression.
for my literal returns 1. Still not working
Please share your full plugin's sources and test project that doesn't work as expected