mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-94821 Don't autoinsert a single completion item if it's provided via middle matching
This commit is contained in:
+6
-1
@@ -17,6 +17,7 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiFormatUtil;
|
||||
import com.intellij.psi.util.PsiFormatUtilBase;
|
||||
@@ -82,8 +83,12 @@ public class JavaLookupElementBuilder {
|
||||
public static LookupElementBuilder forClass(@NotNull PsiClass psiClass,
|
||||
final String lookupString,
|
||||
final boolean withLocation) {
|
||||
final LookupElementBuilder builder =
|
||||
LookupElementBuilder builder =
|
||||
LookupElementBuilder.create(psiClass, lookupString).withIcon(psiClass.getIcon(Iconable.ICON_FLAG_VISIBILITY));
|
||||
String name = psiClass.getName();
|
||||
if (StringUtil.isNotEmpty(name)) {
|
||||
builder = builder.withLookupString(name);
|
||||
}
|
||||
if (withLocation) {
|
||||
return builder.withTailText(" (" + PsiFormatUtil.getPackageDisplayName(psiClass) + ")", true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
public class A {
|
||||
void foo(Foo myXxxxxxxxx) {
|
||||
Xxxxx<caret>
|
||||
}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
public class A {
|
||||
void foo(Foo myXxxxxxxxx) {
|
||||
Xxxxx<caret>
|
||||
}
|
||||
}
|
||||
+6
@@ -1310,5 +1310,11 @@ public class ListUtils {
|
||||
assert myFixture.lookupElementStrings.containsAll(['foo', 'bar'])
|
||||
}
|
||||
|
||||
public void testDontAutoInsertMiddleMatch() {
|
||||
configure()
|
||||
checkResult()
|
||||
assert lookup.items.size() == 1
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
+1
@@ -395,6 +395,7 @@ public class CodeCompletionHandlerBase {
|
||||
final AutoCompletionPolicy policy = getAutocompletionPolicy(item);
|
||||
if (policy == AutoCompletionPolicy.NEVER_AUTOCOMPLETE) return AutoCompletionDecision.SHOW_LOOKUP;
|
||||
if (policy == AutoCompletionPolicy.ALWAYS_AUTOCOMPLETE) return AutoCompletionDecision.insertItem(item);
|
||||
if (!indicator.getLookup().itemMatcher(item).isStartMatch(item)) return AutoCompletionDecision.SHOW_LOOKUP;
|
||||
}
|
||||
if (!isAutocompleteOnInvocation(parameters.getCompletionType())) {
|
||||
return AutoCompletionDecision.SHOW_LOOKUP;
|
||||
|
||||
+21
-1
@@ -5,11 +5,13 @@ import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.completion.PrefixMatcher;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.codeStyle.MinusculeMatcher;
|
||||
import com.intellij.psi.codeStyle.NameUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
@@ -18,6 +20,7 @@ import org.jetbrains.annotations.TestOnly;
|
||||
*/
|
||||
public class CamelHumpMatcher extends PrefixMatcher {
|
||||
private final MinusculeMatcher myMatcher;
|
||||
private final MinusculeMatcher myCaseInsensitiveMatcher;
|
||||
private final boolean myCaseSensitive;
|
||||
private static boolean ourForceStartMatching;
|
||||
|
||||
@@ -30,6 +33,7 @@ public class CamelHumpMatcher extends PrefixMatcher {
|
||||
super(prefix);
|
||||
myCaseSensitive = caseSensitive;
|
||||
myMatcher = createMatcher(myCaseSensitive);
|
||||
myCaseInsensitiveMatcher = createMatcher(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,6 +41,22 @@ public class CamelHumpMatcher extends PrefixMatcher {
|
||||
return myMatcher.isStartMatch(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStartMatch(LookupElement element) {
|
||||
if (super.isStartMatch(element)) {
|
||||
return true;
|
||||
}
|
||||
if (element.isCaseSensitive()) {
|
||||
return false;
|
||||
}
|
||||
return ContainerUtil.or(element.getAllLookupStrings(), new Condition<String>() {
|
||||
@Override
|
||||
public boolean value(String s) {
|
||||
return myCaseInsensitiveMatcher.isStartMatch(s);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean prefixMatches(@NotNull final String name) {
|
||||
return myMatcher.matches(name);
|
||||
@@ -53,7 +73,7 @@ public class CamelHumpMatcher extends PrefixMatcher {
|
||||
return true;
|
||||
}
|
||||
if (itemCaseInsensitive && CodeInsightSettings.ALL != CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) {
|
||||
if (createMatcher(false).matches(name)) {
|
||||
if (myCaseInsensitiveMatcher.matches(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user