mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
case-insensitive matching in autopopup when there are no case-sensitive variants
This commit is contained in:
+5
-5
@@ -220,15 +220,14 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
|
||||
addKeywords(parameters, result);
|
||||
|
||||
addAllClasses(parameters, result, position, inheritors);
|
||||
addAllClasses(parameters, result, inheritors);
|
||||
result.stopHere();
|
||||
}
|
||||
|
||||
public static void addAllClasses(CompletionParameters parameters,
|
||||
final CompletionResultSet result,
|
||||
PsiElement position,
|
||||
final InheritorsHolder inheritors) {
|
||||
if (shouldRunClassNameCompletion(result, position)) {
|
||||
if (shouldRunClassNameCompletion(result, parameters)) {
|
||||
JavaClassNameCompletionContributor.addAllClasses(parameters, result, new Consumer<LookupElement>() {
|
||||
@Override
|
||||
public void consume(LookupElement element) {
|
||||
@@ -314,7 +313,8 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean shouldRunClassNameCompletion(CompletionResultSet result, PsiElement position) {
|
||||
private static boolean shouldRunClassNameCompletion(CompletionResultSet result, CompletionParameters parameters) {
|
||||
PsiElement position = parameters.getPosition();
|
||||
final PsiElement parent = position.getParent();
|
||||
if (!(parent instanceof PsiJavaCodeReferenceElement)) return false;
|
||||
if (((PsiJavaCodeReferenceElement)parent).getQualifier() != null) return false;
|
||||
@@ -331,7 +331,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
return false;
|
||||
}
|
||||
|
||||
return StringUtil.isNotEmpty(result.getPrefixMatcher().getPrefix());
|
||||
return StringUtil.isCapitalized(result.getPrefixMatcher().getPrefix()) || parameters.getInvocationCount() >= 2 || parameters.relaxMatching();
|
||||
}
|
||||
|
||||
private static void completeAnnotationAttributeName(CompletionResultSet result, PsiElement insertedElement,
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ public class JavaDocCompletionContributor extends CompletionContributor {
|
||||
result.addElement(item);
|
||||
}
|
||||
|
||||
JavaCompletionContributor.addAllClasses(parameters, result, position, new InheritorsHolder(position, result));
|
||||
JavaCompletionContributor.addAllClasses(parameters, result, new InheritorsHolder(position, result));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+13
-3
@@ -29,9 +29,10 @@ public class CompletionParameters {
|
||||
private final CompletionType myCompletionType;
|
||||
private final int myOffset;
|
||||
private final int myInvocationCount;
|
||||
private final boolean myRelaxedMatching;
|
||||
|
||||
protected CompletionParameters(@NotNull final PsiElement position, @NotNull final PsiFile originalFile,
|
||||
final CompletionType completionType, int offset, final int invocationCount) {
|
||||
final CompletionType completionType, int offset, final int invocationCount, final boolean relaxedMatching) {
|
||||
assert offset >= position.getTextRange().getStartOffset();
|
||||
myPosition = position;
|
||||
assert position.isValid();
|
||||
@@ -39,14 +40,19 @@ public class CompletionParameters {
|
||||
myCompletionType = completionType;
|
||||
myOffset = offset;
|
||||
myInvocationCount = invocationCount;
|
||||
myRelaxedMatching = relaxedMatching;
|
||||
}
|
||||
|
||||
public CompletionParameters withType(CompletionType type) {
|
||||
return new CompletionParameters(myPosition, myOriginalFile, type, myOffset, myInvocationCount);
|
||||
return new CompletionParameters(myPosition, myOriginalFile, type, myOffset, myInvocationCount, myRelaxedMatching);
|
||||
}
|
||||
|
||||
public CompletionParameters withInvocationCount(int newCount) {
|
||||
return new CompletionParameters(myPosition, myOriginalFile, myCompletionType, myOffset, newCount);
|
||||
return new CompletionParameters(myPosition, myOriginalFile, myCompletionType, myOffset, newCount, myRelaxedMatching);
|
||||
}
|
||||
|
||||
public CompletionParameters withRelaxedMatching() {
|
||||
return new CompletionParameters(myPosition, myOriginalFile, myCompletionType, myOffset, myInvocationCount, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -82,4 +88,8 @@ public class CompletionParameters {
|
||||
public int getInvocationCount() {
|
||||
return myInvocationCount;
|
||||
}
|
||||
|
||||
public boolean relaxMatching() {
|
||||
return myRelaxedMatching;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-3
@@ -53,6 +53,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.NameUtil;
|
||||
import com.intellij.psi.impl.PsiFileEx;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
@@ -291,11 +292,20 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
indicator.duringCompletion(initContext);
|
||||
ProgressManager.checkCanceled();
|
||||
|
||||
data.set(CompletionService.getCompletionService().performCompletion(parameters, new Consumer<LookupElement>() {
|
||||
Consumer<LookupElement> consumer = new Consumer<LookupElement>() {
|
||||
public void consume(final LookupElement lookupElement) {
|
||||
indicator.addItem(lookupElement);
|
||||
}
|
||||
}));
|
||||
};
|
||||
LookupElement[] result = CompletionService.getCompletionService().performCompletion(parameters, consumer);
|
||||
if (NameUtil.isUseMinusculeHumpMatcher() && parameters.getInvocationCount() == 0) {
|
||||
if (result.length == 0) {
|
||||
result = CompletionService.getCompletionService().performCompletion(parameters.withRelaxedMatching(), consumer);
|
||||
} else {
|
||||
indicator.restartOnEmpty = true;
|
||||
}
|
||||
}
|
||||
data.set(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -347,7 +357,7 @@ public class CodeCompletionHandlerBase implements CodeInsightActionHandler {
|
||||
LOG.error("wrong text: copy='" + fileCopy.getText() + "'; element='" + insertedElement.getText() + "'; range=" + range);
|
||||
}
|
||||
|
||||
return new CompletionParameters(insertedElement, fileCopy.getOriginalFile(), myCompletionType, offset, invocationCount);
|
||||
return new CompletionParameters(insertedElement, fileCopy.getOriginalFile(), myCompletionType, offset, invocationCount, false);
|
||||
}
|
||||
|
||||
private AutoCompletionDecision shouldAutoComplete(
|
||||
|
||||
+7
-2
@@ -18,6 +18,7 @@ package com.intellij.codeInsight.completion;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl;
|
||||
import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler;
|
||||
import com.intellij.codeInsight.hint.EditorHintListener;
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.codeInsight.lookup.*;
|
||||
@@ -399,7 +400,7 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
Disposer.dispose(myQueue);
|
||||
|
||||
CompletionProgressIndicator currentCompletion = CompletionServiceImpl.getCompletionService().getCurrentCompletion();
|
||||
assert currentCompletion == this : currentCompletion + "!=" + this;
|
||||
LOG.assertTrue(currentCompletion == this, currentCompletion + "!=" + this);
|
||||
CompletionServiceImpl.getCompletionService().setCurrentCompletion(null);
|
||||
|
||||
CompletionServiceImpl.assertPhase(CompletionPhase.BgCalculation.class, CompletionPhase.ItemsCalculated.class, CompletionPhase.Synchronous.class, CompletionPhase.Restarted.class);
|
||||
@@ -573,6 +574,8 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
}
|
||||
}
|
||||
|
||||
public boolean restartOnEmpty = false;
|
||||
|
||||
public void prefixUpdated() {
|
||||
final CharSequence text = myEditor.getDocument().getCharsSequence();
|
||||
final int caretOffset = myEditor.getCaretModel().getOffset();
|
||||
@@ -585,7 +588,9 @@ public class CompletionProgressIndicator extends ProgressIndicatorBase implement
|
||||
}
|
||||
}
|
||||
|
||||
hideAutopopupIfMeaningless();
|
||||
if (hideAutopopupIfMeaningless() && restartOnEmpty) {
|
||||
CompletionAutoPopupHandler.scheduleAutoPopup(getProject(), myEditor, getParameters().getOriginalFile());
|
||||
}
|
||||
updateFocus();
|
||||
}
|
||||
|
||||
|
||||
+10
-4
@@ -28,13 +28,15 @@ public class CamelHumpMatcher extends PrefixMatcher {
|
||||
private NameUtil.Matcher myMatcher;
|
||||
private final boolean myCaseSensitive;
|
||||
private final int currentSetting;
|
||||
private final boolean myRelaxedMatching;
|
||||
|
||||
public CamelHumpMatcher(@NotNull final String prefix) {
|
||||
this(prefix, true);
|
||||
this(prefix, true, false);
|
||||
}
|
||||
|
||||
public CamelHumpMatcher(String prefix, boolean caseSensitive) {
|
||||
public CamelHumpMatcher(String prefix, boolean caseSensitive, boolean relaxedMatching) {
|
||||
super(prefix);
|
||||
myRelaxedMatching = relaxedMatching;
|
||||
currentSetting = CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE;
|
||||
myCaseSensitive = caseSensitive;
|
||||
}
|
||||
@@ -47,7 +49,7 @@ public class CamelHumpMatcher extends PrefixMatcher {
|
||||
ourLastCompletionCaseSetting = currentSetting;
|
||||
}
|
||||
|
||||
NameUtil.Matcher pattern = ourPatternCache.get(myPrefix);
|
||||
NameUtil.Matcher pattern = ourPatternCache.get(myRelaxedMatching + myPrefix);
|
||||
if (pattern == null) {
|
||||
pattern = createCamelHumpsMatcher();
|
||||
ourPatternCache.put(myPrefix, pattern);
|
||||
@@ -81,7 +83,7 @@ public class CamelHumpMatcher extends PrefixMatcher {
|
||||
|
||||
@NotNull
|
||||
public PrefixMatcher cloneWithPrefix(@NotNull final String prefix) {
|
||||
return new CamelHumpMatcher(prefix);
|
||||
return new CamelHumpMatcher(prefix, myCaseSensitive, myRelaxedMatching);
|
||||
}
|
||||
|
||||
private NameUtil.Matcher createCamelHumpsMatcher() {
|
||||
@@ -89,6 +91,10 @@ public class CamelHumpMatcher extends PrefixMatcher {
|
||||
return NameUtil.buildCompletionMatcher(myPrefix, 0, true, true);
|
||||
}
|
||||
|
||||
if (myRelaxedMatching) {
|
||||
return NameUtil.buildCompletionMatcher(myPrefix, 0, true, true);
|
||||
}
|
||||
|
||||
switch (CodeInsightSettings.getInstance().COMPLETION_CASE_SENSITIVE) {
|
||||
case CodeInsightSettings.NONE:
|
||||
return NameUtil.buildCompletionMatcher(myPrefix, 0, true, true);
|
||||
|
||||
+2
-2
@@ -82,7 +82,7 @@ public class CompletionServiceImpl extends CompletionService{
|
||||
final PsiElement position = parameters.getPosition();
|
||||
final String prefix = CompletionData.findPrefixStatic(position, parameters.getOffset());
|
||||
final String textBeforePosition = parameters.getPosition().getContainingFile().getText().substring(0, parameters.getOffset());
|
||||
return new CompletionResultSetImpl(consumer, textBeforePosition, new CamelHumpMatcher(prefix), contributor, defaultSorter(parameters), null);
|
||||
return new CompletionResultSetImpl(consumer, textBeforePosition, new CamelHumpMatcher(prefix, true, parameters.relaxMatching()), contributor, defaultSorter(parameters), null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -160,7 +160,7 @@ public class CompletionServiceImpl extends CompletionService{
|
||||
@NotNull
|
||||
@Override
|
||||
public CompletionResultSet caseInsensitive() {
|
||||
return withPrefixMatcher(new CamelHumpMatcher(getPrefixMatcher().getPrefix(), false));
|
||||
return withPrefixMatcher(new CamelHumpMatcher(getPrefixMatcher().getPrefix(), false, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+5
-1
@@ -76,6 +76,11 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate {
|
||||
return Result.CONTINUE;
|
||||
}
|
||||
|
||||
scheduleAutoPopup(project, editor, file);
|
||||
return Result.STOP;
|
||||
}
|
||||
|
||||
public static void scheduleAutoPopup(final Project project, final Editor editor, final PsiFile file) {
|
||||
final boolean isMainEditor = FileEditorManager.getInstance(project).getSelectedTextEditor() == editor;
|
||||
|
||||
final CompletionPhase.AutoPopupAlarm phase = new CompletionPhase.AutoPopupAlarm();
|
||||
@@ -95,7 +100,6 @@ public class CompletionAutoPopupHandler extends TypedHandlerDelegate {
|
||||
}
|
||||
};
|
||||
AutoPopupController.getInstance(project).invokeAutoPopupRunnable(request, CodeInsightSettings.getInstance().AUTO_LOOKUP_DELAY);
|
||||
return Result.STOP;
|
||||
}
|
||||
|
||||
public static void invokeAutoPopupCompletion(Project project, final Editor editor) {
|
||||
|
||||
+1
-1
@@ -453,7 +453,7 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
});
|
||||
|
||||
if (StringUtil.isNotEmpty(result.getPrefixMatcher().getPrefix())) {
|
||||
if (StringUtil.isCapitalized(result.getPrefixMatcher().getPrefix()) || parameters.getInvocationCount() >= 2 || parameters.relaxMatching()) {
|
||||
addAllClasses(parameters, result, inheritors);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user