mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-90349 Auto-completion should always prefer exact match
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
public class Foo {
|
||||
private int size;
|
||||
|
||||
public int size() { return size; }
|
||||
|
||||
public boolean isEmpty() { return size<caret>
|
||||
+7
@@ -12,6 +12,7 @@ import com.intellij.codeInsight.lookup.LookupElementPresentation
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl
|
||||
import com.intellij.ide.ui.UISettings
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.PsiField
|
||||
import com.intellij.psi.PsiMethod
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager
|
||||
import com.intellij.psi.statistics.StatisticsManager
|
||||
@@ -446,4 +447,10 @@ import java.lang.annotation.Target;
|
||||
assertPreferredItems(0, '_goo2', '_goo1')
|
||||
}
|
||||
|
||||
public void testPreferFieldToMethod() {
|
||||
checkPreferredItems(0, 'size', 'size')
|
||||
assert lookup.items[0].object instanceof PsiField
|
||||
assert lookup.items[1].object instanceof PsiMethod
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-1
@@ -144,10 +144,16 @@ public class CompletionLookupArranger extends LookupArranger {
|
||||
}
|
||||
classifier.addElement(element);
|
||||
|
||||
final String invariant = presentation.getItemText() + "###" + presentation.getTailText() + "###" + presentation.getTypeText();
|
||||
final String invariant = presentation.getItemText() + "###" + getTailTextOrSpace(presentation) + "###" + presentation.getTypeText();
|
||||
element.putUserData(PRESENTATION_INVARIANT, invariant);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String getTailTextOrSpace(LookupElementPresentation presentation) {
|
||||
String tailText = presentation.getTailText();
|
||||
return tailText == null || tailText.isEmpty() ? " " : tailText;
|
||||
}
|
||||
|
||||
private static List<LookupElement> sortByPresentation(Iterable<LookupElement> source) {
|
||||
ArrayList<LookupElement> result = ContainerUtil.newArrayList(source);
|
||||
ContainerUtil.sort(result, new Comparator<LookupElement>() {
|
||||
|
||||
Reference in New Issue
Block a user