Grouping results of CustomUsageSearcher
I have added a CustomUsageSearcher which returns non-navigatable results. But every result is shown in the usage view tree as a leaf below a "1 results" node:
I used EP com.intellij.fileStructureGroupRuleProvider which allows me to group the results under each node but I still have a first-level node for every usage:
I use two grouping rules with orders 0 and 1. How can I group results so that all are below the first level group, some in a couple of second level groups and of those some in multiple third level groups. So I want e.g. "13 results", two "A project" nodes and in those file nodes which contain leaves.
I assume I have to create one ProjectUsageGroup for each project node and ClassUsageGroup for each class node in that but I'm still unclear on the top-level grouping.
My usages implement UsageInFile and return a dummy file.
Thanks.
Please sign in to leave a comment.
Hi Simon,
Please provide your current implementations snippets.
Hi Karol,
sure, thank you.
My CustomUsageSearcher:
My Usage:
Andy my GroupRulePRovider
While we're at it, I would also like to show a preview for the results but got stuck. It looks like this only works with PsiElements with an actual file behind it. I debugged into UsagePreviewPanel but `com.intellij.usages.impl.UsagePreviewPanel#resetEditor` returned because the it is unable to find the document behind my `LightVirtualFile` (even when my usage returned one with content). Should I open a new thread for that?
Thank you, it's appreciated.
Hi Simon,
Please start with implementing equals methods for your usage groups so that they are equal for different usages, and check if it solves the issue.
That didn't help. Neither method is actually called. I also already tried using constants for the groups which didn't help either.
I think the problem is related to `com.intellij.usages.impl.GroupNode#insertGroupNode` and `com.intellij.usages.impl.GroupNode#getNodeIndex`. `com.intellij.usages.impl.GroupNode.NodeComparator#compare` returns a negative value when comparing to FileGroupingRules:
That way a new node is created for each of the usages. I might be completely wrong though ;-)
Yaaaay I got it working! The problem was that `de.sist.tph.intellij.breakingapi.nativeusage.ReferenceUsage#getFile` always returned a new instance of VirtualFile. I replaced that with a constant and now it's working.
If anybody else by any chance finds this threads and wonders (like me) how to show a preview:
I let my Usage implement UsageProvider and return this:
The important missing part for me was the "true" parameter.