Search in sources :

Example 1 with CompletionSorterImpl

use of com.intellij.codeInsight.completion.impl.CompletionSorterImpl in project intellij-community by JetBrains.

the class CompletionLookupArranger method addElement.

@Override
public void addElement(LookupElement element, LookupElementPresentation presentation) {
    StatisticsWeigher.clearBaseStatisticsInfo(element);
    PresentationInvariant invariant = new PresentationInvariant(presentation.getItemText(), presentation.getTailText(), presentation.getTypeText());
    element.putUserData(PRESENTATION_INVARIANT, invariant);
    element.putUserData(GLOBAL_PRESENTATION_INVARIANT, invariant);
    CompletionSorterImpl sorter = obtainSorter(element);
    Classifier<LookupElement> classifier = myClassifiers.get(sorter);
    if (classifier == null) {
        myClassifiers.put(sorter, classifier = sorter.buildClassifier(new EmptyClassifier()));
    }
    ProcessingContext context = createContext(true);
    classifier.addElement(element, context);
    super.addElement(element, presentation);
    trimToLimit(context);
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) CompletionSorterImpl(com.intellij.codeInsight.completion.impl.CompletionSorterImpl) LiveTemplateLookupElement(com.intellij.codeInsight.template.impl.LiveTemplateLookupElement)

Example 2 with CompletionSorterImpl

use of com.intellij.codeInsight.completion.impl.CompletionSorterImpl in project intellij-community by JetBrains.

the class CompletionLookupArranger method getRelevanceObjects.

@NotNull
@Override
public Map<LookupElement, List<Pair<String, Object>>> getRelevanceObjects(@NotNull Iterable<LookupElement> items, boolean hideSingleValued) {
    Map<LookupElement, List<Pair<String, Object>>> map = ContainerUtil.newIdentityHashMap();
    MultiMap<CompletionSorterImpl, LookupElement> inputBySorter = groupItemsBySorter(items);
    int sorterNumber = 0;
    for (CompletionSorterImpl sorter : inputBySorter.keySet()) {
        sorterNumber++;
        Collection<LookupElement> thisSorterItems = inputBySorter.get(sorter);
        for (LookupElement element : thisSorterItems) {
            map.put(element, ContainerUtil.newArrayList(new Pair<>("frozen", myFrozenItems.contains(element)), new Pair<>("sorter", sorterNumber)));
        }
        ProcessingContext context = createContext(false);
        Classifier<LookupElement> classifier = myClassifiers.get(sorter);
        while (classifier != null) {
            final THashSet<LookupElement> itemSet = ContainerUtil.newIdentityTroveSet(thisSorterItems);
            List<LookupElement> unsortedItems = ContainerUtil.filter(myItems, lookupElement -> itemSet.contains(lookupElement));
            List<Pair<LookupElement, Object>> pairs = classifier.getSortingWeights(unsortedItems, context);
            if (!hideSingleValued || !haveSameWeights(pairs)) {
                for (Pair<LookupElement, Object> pair : pairs) {
                    map.get(pair.first).add(Pair.create(classifier.getPresentableName(), pair.second));
                }
            }
            classifier = classifier.getNext();
        }
    }
    //noinspection unchecked
    Map<LookupElement, List<Pair<String, Object>>> result = new com.intellij.util.containers.hash.LinkedHashMap(EqualityPolicy.IDENTITY);
    for (LookupElement item : items) {
        result.put(item, map.get(item));
    }
    return result;
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) CompletionSorterImpl(com.intellij.codeInsight.completion.impl.CompletionSorterImpl) LiveTemplateLookupElement(com.intellij.codeInsight.template.impl.LiveTemplateLookupElement) SmartList(com.intellij.util.SmartList) Pair(com.intellij.openapi.util.Pair) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with CompletionSorterImpl

use of com.intellij.codeInsight.completion.impl.CompletionSorterImpl in project intellij-community by JetBrains.

the class CompletionLookupArranger method sortByRelevance.

private Iterable<LookupElement> sortByRelevance(MultiMap<CompletionSorterImpl, LookupElement> inputBySorter) {
    final List<Iterable<LookupElement>> byClassifier = ContainerUtil.newArrayList();
    for (CompletionSorterImpl sorter : myClassifiers.keySet()) {
        ProcessingContext context = createContext(false);
        byClassifier.add(myClassifiers.get(sorter).classify(inputBySorter.get(sorter), context));
    }
    //noinspection unchecked
    return ContainerUtil.concat(byClassifier.toArray(new Iterable[byClassifier.size()]));
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) CompletionSorterImpl(com.intellij.codeInsight.completion.impl.CompletionSorterImpl)

Example 4 with CompletionSorterImpl

use of com.intellij.codeInsight.completion.impl.CompletionSorterImpl in project intellij-community by JetBrains.

the class CompletionLookupArranger method removeItem.

private void removeItem(LookupElement element, ProcessingContext context) {
    CompletionSorterImpl sorter = obtainSorter(element);
    Classifier<LookupElement> classifier = myClassifiers.get(sorter);
    classifier.removeElement(element, context);
}
Also used : CompletionSorterImpl(com.intellij.codeInsight.completion.impl.CompletionSorterImpl) LiveTemplateLookupElement(com.intellij.codeInsight.template.impl.LiveTemplateLookupElement)

Example 5 with CompletionSorterImpl

use of com.intellij.codeInsight.completion.impl.CompletionSorterImpl in project intellij-community by JetBrains.

the class CompletionLookupArranger method arrangeItems.

@Override
public Pair<List<LookupElement>, Integer> arrangeItems(@NotNull Lookup lookup, boolean onExplicitAction) {
    List<LookupElement> items = getMatchingItems();
    MultiMap<CompletionSorterImpl, LookupElement> itemsBySorter = groupItemsBySorter(items);
    LookupElement relevantSelection = findMostRelevantItem(itemsBySorter);
    LookupImpl lookupImpl = (LookupImpl) lookup;
    List<LookupElement> listModel = isAlphaSorted() ? sortByPresentation(items) : fillModelByRelevance(lookupImpl, ContainerUtil.newIdentityTroveSet(items), itemsBySorter, relevantSelection);
    int toSelect = getItemToSelect(lookupImpl, listModel, onExplicitAction, relevantSelection);
    LOG.assertTrue(toSelect >= 0);
    addDummyItems(items.size() - listModel.size(), listModel);
    return new Pair<>(listModel, toSelect);
}
Also used : LookupImpl(com.intellij.codeInsight.lookup.impl.LookupImpl) CompletionSorterImpl(com.intellij.codeInsight.completion.impl.CompletionSorterImpl) LiveTemplateLookupElement(com.intellij.codeInsight.template.impl.LiveTemplateLookupElement) Pair(com.intellij.openapi.util.Pair)

Aggregations

CompletionSorterImpl (com.intellij.codeInsight.completion.impl.CompletionSorterImpl)5 LiveTemplateLookupElement (com.intellij.codeInsight.template.impl.LiveTemplateLookupElement)4 ProcessingContext (com.intellij.util.ProcessingContext)3 Pair (com.intellij.openapi.util.Pair)2 LookupImpl (com.intellij.codeInsight.lookup.impl.LookupImpl)1 SmartList (com.intellij.util.SmartList)1 NotNull (org.jetbrains.annotations.NotNull)1