mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
preselect the most relevant item (e.g. finally>final, swing getComponents>getComponent, IDEA-82206)
This commit is contained in:
+6
@@ -0,0 +1,6 @@
|
||||
class A {
|
||||
{
|
||||
try {}
|
||||
fin<caret>x
|
||||
}
|
||||
}
|
||||
+8
-4
@@ -101,7 +101,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
public void testDispreferImpls() throws Throwable {
|
||||
myFixture.addClass("package foo; public class Xxx {}");
|
||||
configureSecondCompletion();
|
||||
assertPreferredItems(0, "Xxx", "XxxEx", "XxxImpl", "Xxy");
|
||||
assertPreferredItems(1, "Xxx", "XxxEx", "XxxImpl", "Xxy");
|
||||
}
|
||||
|
||||
public void testPreferOwnInnerClasses() throws Throwable {
|
||||
@@ -128,7 +128,7 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
myFixture.addClass("package foo; public interface XaYa {}");
|
||||
myFixture.addClass("package foo; public interface XyYa {}");
|
||||
configureSecondCompletion();
|
||||
assertPreferredItems(0, "XaYa", "XaYaEx", "XaYaImpl", "XyYa", "XyYaXa");
|
||||
assertPreferredItems(1, "XaYa", "XaYaEx", "XaYaImpl", "XyYa", "XyYaXa");
|
||||
}
|
||||
|
||||
public void testPreferLessParameters() throws Throwable {
|
||||
@@ -218,8 +218,12 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
checkPreferredItems(0, "FooClass", "Foo_Intf");
|
||||
}
|
||||
|
||||
public void testPreferClassOverItsStaticMembers() {
|
||||
checkPreferredItems(0, "Zoo");
|
||||
public void testPreferClassStaticMembers() {
|
||||
checkPreferredItems(1, "Zoo", "Zoo.A", "Zoo.B", "Zoo.C", "Zoo.D", "Zoo.E", "Zoo.F", "Zoo.G", "Zoo.H");
|
||||
}
|
||||
|
||||
public void testPreferFinallyToFinal() {
|
||||
checkPreferredItems(1, "final", "finally");
|
||||
}
|
||||
|
||||
public void testPreferReturn() {
|
||||
|
||||
+10
-6
@@ -49,6 +49,7 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
private static final Alarm ourStatsAlarm = new Alarm(ApplicationManager.getApplication());
|
||||
private static final Key<String> PRESENTATION_INVARIANT = Key.create("PRESENTATION_INVARIANT");
|
||||
private static final int MAX_PREFERRED_COUNT = 5;
|
||||
public static final Key<Boolean> PURE_RELEVANCE = Key.create("PURE_RELEVANCE");
|
||||
private final List<LookupElement> myFrozenItems = new ArrayList<LookupElement>();
|
||||
private static final String SELECTED = "selected";
|
||||
static final String IGNORED = "ignored";
|
||||
@@ -187,7 +188,7 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
}
|
||||
ArrayList<LookupElement> listModel = new ArrayList<LookupElement>(model);
|
||||
|
||||
return new Pair<List<LookupElement>, Integer>(listModel, getItemToSelect(lookup, byRelevance, listModel));
|
||||
return new Pair<List<LookupElement>, Integer>(listModel, getItemToSelect(lookup, listModel, inputBySorter));
|
||||
}
|
||||
|
||||
|
||||
@@ -196,7 +197,7 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
return new CompletionLookupArranger(myParameters, myProcess);
|
||||
}
|
||||
|
||||
private int getItemToSelect(Lookup lookup, List<LookupElement> byRelevance, List<LookupElement> items) {
|
||||
private int getItemToSelect(Lookup lookup, List<LookupElement> items, MultiMap<CompletionSorterImpl, LookupElement> inputBySorter) {
|
||||
if (items.isEmpty() || !lookup.isFocused()) {
|
||||
return 0;
|
||||
}
|
||||
@@ -226,10 +227,13 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
}
|
||||
|
||||
final CompletionPreselectSkipper[] skippers = CompletionPreselectSkipper.EP_NAME.getExtensions();
|
||||
|
||||
for (LookupElement element : byRelevance) {
|
||||
if (!shouldSkip(skippers, element)) {
|
||||
return items.indexOf(element);
|
||||
for (CompletionSorterImpl sorter : myClassifiers.keySet()) {
|
||||
ProcessingContext context = new ProcessingContext();
|
||||
context.put(PURE_RELEVANCE, Boolean.TRUE);
|
||||
for (LookupElement element : myClassifiers.get(sorter).classify(inputBySorter.get(sorter), context)) {
|
||||
if (!shouldSkip(skippers, element)) {
|
||||
return items.indexOf(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.completion.impl;
|
||||
|
||||
import com.intellij.codeInsight.completion.CompletionLookupArranger;
|
||||
import com.intellij.codeInsight.lookup.Classifier;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
@@ -75,6 +76,9 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
|
||||
|
||||
@Override
|
||||
public Iterable<LookupElement> classify(Iterable<LookupElement> source, ProcessingContext context) {
|
||||
if (context.get(CompletionLookupArranger.PURE_RELEVANCE) == Boolean.TRUE) {
|
||||
return myNext.classify(source, context);
|
||||
}
|
||||
return liftShorterElements(source, new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY), context);
|
||||
}
|
||||
|
||||
@@ -116,8 +120,8 @@ class LiftShorterItemsClassifier extends Classifier<LookupElement> {
|
||||
|
||||
@Override
|
||||
public void describeItems(LinkedHashMap<LookupElement, StringBuilder> map, ProcessingContext context) {
|
||||
final HashSet<LookupElement> lifted = new HashSet<LookupElement>();
|
||||
liftShorterElements(new ArrayList<LookupElement>(map.keySet()), new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY), new ProcessingContext());
|
||||
final THashSet<LookupElement> lifted = new THashSet<LookupElement>(TObjectHashingStrategy.IDENTITY);
|
||||
liftShorterElements(new ArrayList<LookupElement>(map.keySet()), lifted, new ProcessingContext());
|
||||
if (!lifted.isEmpty()) {
|
||||
for (LookupElement element : map.keySet()) {
|
||||
final StringBuilder builder = map.get(element);
|
||||
|
||||
Reference in New Issue
Block a user