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);
}
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;
}
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()]));
}
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);
}
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);
}
Aggregations