Custom name for Find Usages of symbol

I've implemented com.intellij.lang.findUsages.FindUsagesProvider and com.intellij.openapi.application.QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> for finding usages of LeafPsiElement - value element of YAMLKeyValue (YAML plugin). I want to provide symbol name for popup title in Find Usages - actually popup title looks like this:
usages_title.png
and I would like to have it like this one:
usages_title2.png
How can I change symbol name in this title?

0
4 comments

Hi,

you can register a custom com.intellij.psi.ElementDescriptionProvider.
Here match the getElementDescription method calls where the location is instanceOf com.intellij.usageView.UsageViewLongNameLocation and provide the string that you prefer.

Something like:

public class CustomElementDescriptionProvider implements com.intellij.psi.ElementDescriptionProvider {
    @Nullable
    @Override
    public String getElementDescription(@NotNull PsiElement element, @NotNull ElementDescriptionLocation location) {
        if(isTheElementThatShouldBeDescribed(element) && location instanceof UsageViewLongNameLocation)
            return "property codeName";
        return null;
    }
}


This should do the job

0

Hmm,
I've implemented that interface like this:

public class ComponentDescriptionProvider implements ElementDescriptionProvider {     @Nullable     @Override     public String getElementDescription(@NotNull PsiElement element, @NotNull ElementDescriptionLocation location) {         if (YamlUtils.isLeafValueFromYamlKeyValue(element)) {             return "value " + element.getText();         }         return null;     } }


Method is called and my value is returned but title is still without this text. Even in Show Usages tab there is still "<anonymous>". It is used as description of searched element but not in the title.
val.PNG

0
  1. you are missing the check on the location type, for this reason the string is replacing many different labels:

            return "value " + element.getText();

0

I've added location check as you suggested and put breakpoint at return point but it is never stops there now - location is not instance of UsageViewLongNameLocation. Probably this works only for Java symbols but I'm looking for unclassified usages of non java symbol.

0

Please sign in to leave a comment.