Sort Completion Result elements

Hi, I always had problems with sorting the completion result elements, could you point in the right direction direction for doing this?
I have an extension point for "completion.contributor", I'm adding my LookupElements to the result and that works fine, but I want to show my elements on top, is this possible?

I've tried adding an extension point for "weigher", and I'm using a code like this:

public class MagicentoPhpWeigher extends CompletionWeigher {

    @Override
    public Integer weigh(@NotNull LookupElement element, @NotNull CompletionLocation location)
    {
        if (location == null) {
            return null;
        }

        Object object = element.getObject();    // we can pass any object inside the LookupElement creator in our MagicentoXmlCompletionContributor
        if(object instanceof String){
            String reference = (String) object;
            if(reference.startsWith("magicento")){
                return -100;
            }
        }
        return null;
    }

}


for some strange reason this was working fine in PHPStorm 5, but not in v6

Thanks !
Enrique.

4 comments

When you add your LookupElement to the CompletionResultSet, you could use such an approach

result.addElement(PrioritizedLookupElement.withPriority(elm, importance));


to give your element different importance level. I struggled with the CompletionWeighter implementation too until I
found this and therefore, I would be intereste in a propper way too.

0

I've tried that but I'm getting weird results, I have a code like this:

int count = 1000;
        for(String name : names){
            LookupElement element = LookupElementBuilder.create("magicento_extends", name)
                    .setPresentableText(name)
                    .setIcon(myIcon);
            elements.add(PrioritizedLookupElement.withPriority(element, count));
            count++;
        }


For example:
Ctrl+Space (first time):
autocomplete-first_time.jpg
Ctrl+Space (second time):
autocomplete-second_time.jpg

Is this the normal/expected behavior?

0

It doesn't seem to be normal. Are all elements in the list added by your contributor? Does the list appear quickly, or shows calculation progress for some time?

0

I think this is solved now just adding "order=first" to my contributor

0

Please sign in to leave a comment.