Name / description of element not shown in usage dialog when using custom FindUsagesHandler

Answered

I have a custom FindUsagesHandler for PsiLiteralExpression elements and a CustomUsageSearcher to find the usages.

Everything works fine but in the place where usually the description of the element is shown the space is empty:

 

It doesn't look like there's code in the FindUsagesHandler for this. How do I get a proper description to show up?

0
9 comments

What is your callback to Processor<? super Usage> processor in com.intellij.find.findUsages.CustomUsageSearcher#processElementUsages implementation?

0
if (referencedElement.getLanguage() != JavaLanguage.INSTANCE) {
            return;
        }
        final UsageDataProvider dataProvider = ReadAction.compute(referencedElement::getProject).getService(UsageDataProvider.class);
        final Map<CustomerProject, Collection<String>> referencesForPsiElement = dataProvider.getReferencesForPsiElement(referencedElement);
        for (Map.Entry<CustomerProject, Collection<String>> entry : referencesForPsiElement.entrySet()) {
            for (String fileName : entry.getValue()) {
                processor.process(new ReferenceUsage(referencedElement, entry.getKey().getName(), fileName));
            }
        }

 

h

0

please clarify, what is

ReferenceUsage
0

Please try wrapping:

processor.process(new com.intellij.usages.UsageInfo2UsageAdapter(new ReferenceUsage(...) );

0

ReferenceUsage doesn't extend UsageInfo. Extending it would clash with UsageInFile. I can give it a try though.

0

Hi Yann Cebron,

that doesn't work for me. I'd have to extend UsageInfo but I don't have any PsiElement that represents the usage. The "usage" is actually an external file. The whole system around UsageInfo and the adapter seems to assume that I have PsiElements as usages.

This also seems to cause https://youtrack.jetbrains.com/issue/IDEA-293793/Custom-usage-class-cannot-be-cast-to-class-com-intellij-usages-U which prevents all usages from being shown when I provide one of my usages.

An additional problem is that now my usages are shown as project usages while before they were (correctly) only shown in "All places".

 

0

Thanks for the update.

I'm afraid it seems I mixed up my previous answers, they probably have nothing to do with your original question about the "searched element" node (not the results nodes).

Please try providing custom ElementDescriptionProvider as described in last paragraph on this page for the searched PsiLiteralExpression: https://plugins.jetbrains.com/docs/intellij/find-usages.html

0

Thanks for the quick response. That worked great!


For future reference: I had to check the type of the ElementDescriptionLocation. If it's UsageViewTypeLocation it's the type shown (in the screenshot "Expression"). Otherwise it may be UsageViewLongNameLocation, UsageViewShortNameLocation or UsageViewNodeTextLocation in which case I return the description of the element for which we searched usages.

0

Please sign in to leave a comment.