PsiReference to PsiFile

Hi.

I'm implementing a reference contributor for a custom XML we have:

<myElement location="yourFile.png"/>

I want "location" to be a reference to a file in your source roots. I already have the VirtualFile and PsiFile for 'location', but I don't know how to get a PsiReference for it. Is there a way to do it?

Thanks in advance!

7 comments

If you're using DOM you can use  GenericAttributeValue<PathReference> getLocation(), eventually using a custom @Converter if you need to extend resolve logic.
If you're using "plain" references in XML PSI, com.intellij.psi.impl.source.resolve.reference.impl.providers.FileReferenceSet or its subclasses will help you.

0

Thank you very much, that was it :)

0

 

Could you elaborate on the approach you took?

I am facing the same problem. I am not sure how to create FileReferenceSet for the text in my attribute

To be more specific, I have something like

<myElement myLocation="myFile.push()">

I need to get the reference to myFile.xml file

Any idea how to create a FileReferenceSet and the corresponding reference to the xml file

I will really appreciate it

0

One sample would be org.jetbrains.idea.devkit.dom.DependencyConfigFileConverter from DevKit plugin

0

Any sample if not using DOM API?

0

You can use "plain" PsiReferenceProvider and return references from FileReferenceSet or just delegate to com.intellij.openapi.paths.PathReferenceProvider#createReferences

0

Hi Yann

 

Thank you for your help

I made good progress. Thanks

0

Please sign in to leave a comment.