Sort code completion variants (using LookupItem)

The getVariants of my PsiReference returns an array of com.intellij.codeInsight.lookup.LookupItem objects.
I done my own implementation of LookupItem and have overwritten the compareTo() method in the hope I can influence the sorting. Strangely this method is never called.

After looking into decompiled code of LookupItemUtil I saw that a new LookupItem is created unless the getObject() method returns a LookupItem itself. So I have overwritten this method to return its own instance, but still I do not achieve the expected result.

Can someone advise on how I can sort the list of code completion variants (using LookupItem)? Or using any other object type.
Appreciate any help.

4 comments
Comment actions Permalink

Simply implement LookupValueWithPriority in your LookupItem-class to provide a sorting order.

0
Comment actions Permalink

Yann, thanks a lot! Works perfectly.
Even though LookupValueWithPriority has only three presets (NORMAL, HIGHER, HIGH), it seem to accept and properly work with different values as well.
Great! Thanks again for the hint.

0
Comment actions Permalink

Yann, thanks a lot! Works perfectly.
Even though LookupValueWithPriority has only three presets (NORMAL, HIGHER, HIGH), it seem to accept and properly work with different values as well.
Great! Thanks again for the hint.


A better way to achieve the same thing is to call setPriority() on a
LookupItem (in IDEA 7). Or to implement completely custom comparing
algorithm in IDEA 8

0
Comment actions Permalink

Thanks Peter! Actually i used the setPriority() approach. Following the hint from Yann, i looked up how this interface is used when creating the LookupItem. The comparing algorithm is also in place, but as i said it is useless for 7.0. Maybe it will be different in 8.0.
Regards,
Dan

0

Please sign in to leave a comment.