Select autocompletion Lookup item by number

I'm trying to make it so the Completion lookup suggestions can be selected by their place in the list. This involves both showing a numbered icon next to them, and selecting the/finishing the selection via a number key press.

The closest I can get this to working is to wait for a lookup to be shown and watch it via a LookupListener, and then hide it and immediately show another with the first 10 items customised - this breaks an assertion in the LookupImpl and isn't very clean.

Have also tried using a CompletionContributor, but I need to replace the first 10 elements not just add others. Any suggestions on how this can be approached?

1
4 comments
Official comment

Unfortunately, there's no dedicated API for that, and I don't see easy ways to achieve this, given that completion internals rely on lookup element identity, and they also change the list sorting quite frequently. The best that comes to my mind is adding some transparent component into LookupImpl on top of the current list, and painting numbers on it, carefully tracking scrolling.

Avatar
Permanently deleted user

CompletionContributor's documentation states:

Q: How do I affect lookup element's appearance (icon, text attributes, etc.)?<br>
A: See {@link LookupElement#renderElement(LookupElementPresentation)}.

and I can see how that works, but I'm not sure where it's expected that this interaction occurs.If I wanted to -  for example - add the same icon to every lookup element in every completion, where would I do that?

If I wanted to sub-class LookupImpl to replace some functionality, is that possible?

0

Question is unclear. Of course you are free to implement your own com.intellij.codeInsight.lookup.LookupElement with any logic you want. 

However, there is a com.intellij.codeInsight.lookup.LookupElementBuilder which allows you to set icon when creating a lookup element.

0

Now that I think more of it, you could substitute cell renderer in LookupImpl#getList.

0

Please sign in to leave a comment.