Is it possible to have a PsiReference resolve to an offset in the target element?
Answered
This may sound like a strange request, but I have a situation where the target of a reference is basically a plain text file, but I know the specific offset in that file that corresponds to the reference. It would be overkill to create a new PSI tree for the target file just to resolve to a specific offset into it, but unfortunately I can't seem to find a way to do this without having a PSI element that starts at the desired offset. Hopefully I'm just missing something?
Please sign in to leave a comment.
You can resolve your reference to an instance of FakePsiElement, redefine it's #navigate method and do the following there:
PsiNavigationSupport.getInstance().createNavigatable(project, virtualFile, offset).navigate(requestFocus)
Thanks, Peter. That's pretty much what I did, though I didn't know about FakePsiElement and rolled my own that overrides getTextRange() and getStartOffset(). I'll migrate that to FakePsiElement. Much appreciated!