Question about creating own PsiReferenceContributor
I'm creating a plugin for our XML configuration, the tags are related through their attribute values. For example:
<sourceTag id="abc"/>
...
<myTag sourceId="abc"/>
My goal is to make the attribute values "abc" of <myTag> clickable, after click the editor should mark and scroll to "<sourceTag>"
I created a subclass of PsiReferenceContributor and register a PsiReferenceProvider with the pattern:
PlatformPatterns.psiElement(XmlAttributeValue.class)
This is my first question:
In document
it says: "Every element which can be renamed or referenced needs to implement com.intellij.psi.PsiNamedElement interface". XmlAttributeValue doesn't implement the interface, is that a problem here? Can I still use it as a pattern? Because I really want to make the attribute value clickable not the attribute name.
In my PsiReferenceProvider.getReferencesByElement() I find the related XmlTag and return its reference with xmlTag.getReference().
This is my second question, is this the correct way to get a reference from PsiElement?
My code works basically, but when I ctrl click on the attribute value, IDEA open the XSD file and mark the definition of the tag <sourceTag> instead... It seems some default behavior overrides my Contributor again.
This is my last question, how can I override this default behavior?
Thank you very much in advance!
Please sign in to leave a comment.
After some test, it can now answer part of my questions:
1. PlatformPatterns.psiElement(XmlAttributeValue.class) works, but the better way is to use the static functions of XmlPatterns.
2. 3. I found an opensource plugin, it doesn't use the xmlTag.getReference(), it create its own subclass of XmlAttributeReference and override the resolve() function to return the attributeImpl object directly. The default implementation returns XmlAttributeDescriptor.getDeclaration() that is way it always open the XSD file.
But I don't know why when I hold ctrl and mouse over my XML property value, there is no underline to indicate it can be clicked. Should I override any other functions of XmlAttributeReference?
Thanks