CompletionContributor: How to show multiple entries with same name?


Suppose I have a CompletionContributor that produces LookupElements with same name, but for distinct symbols. Example:

public class MyLanguageCompletionContributor extends CompletionContributor {

    public MyLanguageCompletionContributor() {
        extend(CompletionType.BASIC, PlatformPatterns.psiElement().withLanguage(MyLanguage.INSTANCE),
                new CompletionProvider<>() {
                    protected void addCompletions(@NotNull CompletionParameters parameters,
                                                  @NotNull ProcessingContext context,
                                                  @NotNull CompletionResultSet result) {

* 'funcTest2' exists on both 'MyModule1' and 'MyModule2' modules

                        LookupElement element = LookupElementBuilder.create("funcTest2")
                                .withTailText("(): void")


                        element = LookupElementBuilder.create("funcTest2")
                                .withTailText("(): void")



Intellij is always grouping these entries and showing only the first one:


So, how can I configure my LookupElement or CompletionContributor to show both entries?



Hi Luiz,

Please check the LookupElementBuilder.equals() method:

It doesn't depend on presentation/typeText which is the only difference in your elements.

This example seems as playing with the API and in the real world, you may want to set e.g., insertHandler which would import Module1 or Module2 in your case, and it would make the completion popup contain both items.


Hi Karol,

Thank you for pointing out the equals() implementation of LookupElementBuilder.

My real CompletionContributor already have an InsertHandler to deal with the auto-import logic, but my mistake was not providing a lookupObject with a correct implementation of hashCode and equals.

//was LookupElementBuilder.create(symbol.getName())
LookupElementBuilder element = LookupElementBuilder.create(symbol, symbol.getName());

Fixing it was enough to solve the problem




Please sign in to leave a comment.