mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-68698 Elements with exactly same prefix (and same proximity) should be placed at the top of the list
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
class FooOCSomething {}
|
||||
class FooObjectCollector {}
|
||||
|
||||
class Foo {
|
||||
{
|
||||
FooOC<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+4
@@ -209,6 +209,10 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
checkPreferredItems(0, "else", "element");
|
||||
}
|
||||
|
||||
public void testPreferMoreMatching() {
|
||||
checkPreferredItems(0, "FooOCSomething", "FooObjectCollector");
|
||||
}
|
||||
|
||||
public void testPreferSamePackageOverImported() {
|
||||
myFixture.addClass("package bar; public class Bar1 {}");
|
||||
myFixture.addClass("package bar; public class Bar2 {}");
|
||||
|
||||
+12
-24
@@ -15,12 +15,11 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.codeStyle.NameUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
@@ -29,27 +28,16 @@ public class PrefixMatchingWeigher extends CompletionWeigher {
|
||||
public Comparable weigh(@NotNull final LookupElement item, @NotNull final CompletionLocation location) {
|
||||
final String prefix = location.getCompletionParameters().getLookup().itemPattern(item);
|
||||
|
||||
if (prefix.isEmpty()) {
|
||||
return 0;
|
||||
final int setting = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE;
|
||||
final NameUtil.MatchingCaseSensitivity sensitivity =
|
||||
setting == CodeInsightSettings.NONE ? NameUtil.MatchingCaseSensitivity.NONE :
|
||||
setting == CodeInsightSettings.FIRST_LETTER ? NameUtil.MatchingCaseSensitivity.FIRST_LETTER : NameUtil.MatchingCaseSensitivity.ALL;
|
||||
final NameUtil.MinusculeMatcher matcher = new NameUtil.MinusculeMatcher(prefix, sensitivity);
|
||||
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (String lookupString : item.getAllLookupStrings()) {
|
||||
max = Math.max(max, matcher.matchingDegree(lookupString));
|
||||
}
|
||||
|
||||
final Set<String> strings = item.getAllLookupStrings();
|
||||
final String prefixHumps = StringUtil.capitalsOnly(prefix);
|
||||
|
||||
if (StringUtil.isNotEmpty(prefixHumps)) {
|
||||
for (String lookupString : strings) {
|
||||
if (StringUtil.capitalsOnly(lookupString).startsWith(prefixHumps)) return 100;
|
||||
}
|
||||
}
|
||||
|
||||
for (String lookupString : strings) {
|
||||
if (lookupString.startsWith(prefix)) return 5;
|
||||
}
|
||||
for (String lookupString : strings) {
|
||||
if (StringUtil.startsWithIgnoreCase(lookupString, prefix)) return 1;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user