PsiReferenceContributor and PsiPlainText


I am developing a plugin for Chef development.
My goal is to reference one file from another file.

For examlpe i would like to make this kind of line in file:
to refernece to specific file with nginx role declaration.

Files containig this text are ruby files (*.rb) but with specific Chef DSL. I would like to treat them just like plain text files. No matter if ruby plugin is installed or not.

I wrote my own PsiReferenceContributor but i have troubles to make a pattern for this kind of text.

I have smth like this:

PsiElementPattern.Capture<PsiElement> elementCapture = PlatformPatterns.psiElement().withText(StandardPatterns.string().contains("role["));

But this calls my PsiReferenceProvider with element of type PsiPlainTextFile. So i am getting whole file instead of that particular line.

How to construct pattern to have smthing like PsiPlainText (containing one selected line of text) given in provider as element instead of whole file?

1 comment
Comment actions Permalink

IntelliJ IDEA does not parse the contents of the plain text files; the only PsiElement inside them is a single PsiPlainText element. Because of that, your reference provider will always get the entire PsiPlainText element. You can restrict your reference to a smaller range by returning it from PsiReference.getRangeInElement().


Please sign in to leave a comment.