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 {

    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;
                return -100;
        return null;


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

Thanks !


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.


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)
            elements.add(PrioritizedLookupElement.withPriority(element, count));

For example:
Ctrl+Space (first time):
Ctrl+Space (second time):

Is this the normal/expected behavior?


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?


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


Please sign in to leave a comment.