ReferenceContributor for XML

Answered

I've implemented PsiReferenceContributor to navigate across specific XML files when a user press CTRL + B on an attribute or tag and if it has more than one usages it shows a popup where all places are listed but the problem that it shows only the name of the attributes so the user can't distinguish between them. Like

customer 
customer
customer
customer

each on a new line.  I've implemented as well PsiReferenceBase and PsiPolyVariantReference all methods are overridden and only three methods are triggered multiResolve and resolve and isSoft.  But methods

getVariants, getCanonicalText, resolveReference, getValue

never triggered.

How can I display custom words?

3 comments
Comment actions Permalink

See com.intellij.codeInsight.navigation.GotoTargetRendererProvider

0
Comment actions Permalink

Implemented, never triggered, nothing changed. 

class XmlGotoTargetRendererProvider : GotoTargetRendererProvider {
override fun getRenderer(element: PsiElement, gotoData: GotoTargetHandler.GotoData): PsiElementListCellRenderer<*> {
return XmlPsiElementListCellRenderer()
}
}
<extensions defaultExtensionNs="com.intellij">
<psi.referenceContributor implementation="com.*.contributor.XmlPsiReferenceContributor" language="XML" id="my" order="first"/>
<gotoTargetRendererProvider implementation="com.*.contributor.XmlGotoTargetRendererProvider" order="first"/>
</extensions>
class XmlPsiElementListCellRenderer : PsiElementListCellRenderer<PsiElement>() {
override fun getElementText(element: PsiElement?): String {
if (element is PsiNamedElement) {
val name: @Nullable String? = element.name
return name ?: ""
}
return element!!.text
}

override fun getContainerText(element: PsiElement?, name: String?): String? {
if (element is NavigationItem) {
val presentation: @Nullable ItemPresentation? = (element as NavigationItem).presentation
if (presentation != null) {
return presentation.locationString
}
}
return null
}

override fun getIconFlags(): Int {
return 0;
}
}

 

0
Comment actions Permalink

Could you link your full plugin's sources?

0

Please sign in to leave a comment.