mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ensure that everything suggested by class name completion is also suggested on second basic completion invocation (IDEA-86517)
This commit is contained in:
+17
-19
@@ -34,7 +34,6 @@ import com.intellij.psi.filters.types.AssignableFromFilter;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.ProcessingContext;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -51,24 +50,23 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
psiElement().afterLeaf(PsiKeyword.EXTENDS, PsiKeyword.SUPER, "&").withParent(
|
||||
psiElement(PsiReferenceList.class).withParent(PsiTypeParameter.class));
|
||||
|
||||
public JavaClassNameCompletionContributor() {
|
||||
extend(CompletionType.CLASS_NAME, psiElement(), new CompletionProvider<CompletionParameters>() {
|
||||
public void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext matchingContext, @NotNull final CompletionResultSet _result) {
|
||||
if (shouldShowSecondSmartCompletionHint(parameters) &&
|
||||
CompletionUtil.shouldShowFeature(parameters, CodeCompletionFeatures.SECOND_CLASS_NAME_COMPLETION)) {
|
||||
CompletionService.getCompletionService().setAdvertisementText(CompletionBundle.message("completion.class.name.hint.2", getActionShortcut(IdeActions.ACTION_CLASS_NAME_COMPLETION)));
|
||||
}
|
||||
|
||||
CompletionResultSet result = _result.withPrefixMatcher(CompletionUtil.findReferenceOrAlphanumericPrefix(parameters));
|
||||
addAllClasses(parameters, parameters.getInvocationCount() <= 1,
|
||||
JavaCompletionSorting.addJavaSorting(parameters, result).getPrefixMatcher(), new Consumer<LookupElement>() {
|
||||
@Override
|
||||
public void consume(LookupElement element) {
|
||||
_result.addElement(element);
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void fillCompletionVariants(CompletionParameters parameters, final CompletionResultSet _result) {
|
||||
if (parameters.isExtendedCompletion()) {
|
||||
if (shouldShowSecondSmartCompletionHint(parameters) &&
|
||||
CompletionUtil.shouldShowFeature(parameters, CodeCompletionFeatures.SECOND_CLASS_NAME_COMPLETION)) {
|
||||
CompletionService.getCompletionService().setAdvertisementText(CompletionBundle.message("completion.class.name.hint.2", getActionShortcut(IdeActions.ACTION_CODE_COMPLETION)));
|
||||
}
|
||||
});
|
||||
|
||||
CompletionResultSet result = _result.withPrefixMatcher(CompletionUtil.findReferenceOrAlphanumericPrefix(parameters));
|
||||
addAllClasses(parameters, parameters.getInvocationCount() <= 1,
|
||||
JavaCompletionSorting.addJavaSorting(parameters, result).getPrefixMatcher(), new Consumer<LookupElement>() {
|
||||
@Override
|
||||
public void consume(LookupElement element) {
|
||||
_result.addElement(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public static void addAllClasses(CompletionParameters parameters,
|
||||
@@ -179,7 +177,7 @@ public class JavaClassNameCompletionContributor extends CompletionContributor {
|
||||
return LangBundle.message("completion.no.suggestions") +
|
||||
"; " +
|
||||
StringUtil.decapitalize(
|
||||
CompletionBundle.message("completion.class.name.hint.2", getActionShortcut(IdeActions.ACTION_CLASS_NAME_COMPLETION)));
|
||||
CompletionBundle.message("completion.class.name.hint.2", getActionShortcut(IdeActions.ACTION_CODE_COMPLETION)));
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ public class JavaGlobalMemberNameCompletionContributor extends CompletionContrib
|
||||
|
||||
@Override
|
||||
public void fillCompletionVariants(CompletionParameters parameters, final CompletionResultSet result) {
|
||||
if (parameters.getCompletionType() != CompletionType.CLASS_NAME) {
|
||||
if (!parameters.isExtendedCompletion()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -1,17 +1,17 @@
|
||||
class Foo {
|
||||
int ELEMENT_A = 1;
|
||||
int ELEMENT_B = 1;
|
||||
int ELEMENT_C = 1;
|
||||
int ELEMENT_D = 1;
|
||||
int ELEMENT_E = 1;
|
||||
int ELEMENT_F = 1;
|
||||
int ELEMENT_G = 1;
|
||||
int ELEMENT_H = 1;
|
||||
int ELEMENT_I = 1;
|
||||
int ELXEMENT_A = 1;
|
||||
int ELXEMENT_B = 1;
|
||||
int ELXEMENT_C = 1;
|
||||
int ELXEMENT_D = 1;
|
||||
int ELXEMENT_E = 1;
|
||||
int ELXEMENT_F = 1;
|
||||
int ELXEMENT_G = 1;
|
||||
int ELXEMENT_H = 1;
|
||||
int ELXEMENT_I = 1;
|
||||
|
||||
|
||||
{
|
||||
El<caret>
|
||||
Elx<caret>
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -287,13 +287,13 @@ public class NormalCompletionOrderingTest extends CompletionSortingTestCase {
|
||||
public void testPreselectMostRelevantInTheMiddleAlpha() {
|
||||
UISettings.getInstance().SORT_LOOKUP_ELEMENTS_LEXICOGRAPHICALLY = true;
|
||||
|
||||
myFixture.addClass("package foo; public class Elaaaaaaaaaaaaaaaaaaaa {}");
|
||||
myFixture.addClass("package foo; public class Elxaaaaaaaaaaaaaaaaaaaa {}");
|
||||
invokeCompletion(getTestName(false) + ".java");
|
||||
myFixture.completeBasic();
|
||||
LookupImpl lookup = getLookup();
|
||||
assertPreferredItems(lookup.getList().getSelectedIndex());
|
||||
assertEquals("Elaaaaaaaaaaaaaaaaaaaa", lookup.getItems().get(0).getLookupString());
|
||||
assertEquals("ELEMENT_A", lookup.getCurrentItem().getLookupString());
|
||||
assertEquals("Elxaaaaaaaaaaaaaaaaaaaa", lookup.getItems().get(0).getLookupString());
|
||||
assertEquals("ELXEMENT_A", lookup.getCurrentItem().getLookupString());
|
||||
}
|
||||
|
||||
public void testReallyAlphaSorting() {
|
||||
|
||||
@@ -98,4 +98,8 @@ public final class CompletionParameters {
|
||||
public CompletionParameters withPosition(PsiElement element, int offset) {
|
||||
return new CompletionParameters(element, myOriginalFile, myCompletionType, offset, myInvocationCount, myLookup);
|
||||
}
|
||||
|
||||
public boolean isExtendedCompletion() {
|
||||
return myCompletionType == CompletionType.CLASS_NAME || myCompletionType == CompletionType.BASIC && myInvocationCount >= 2;
|
||||
}
|
||||
}
|
||||
|
||||
+21
-6
@@ -77,11 +77,15 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
});
|
||||
|
||||
extend(CompletionType.CLASS_NAME, psiElement(), new CompletionProvider<CompletionParameters>() {
|
||||
CompletionProvider<CompletionParameters> provider = new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull final CompletionParameters parameters,
|
||||
ProcessingContext context,
|
||||
@NotNull final CompletionResultSet _result) {
|
||||
if (!parameters.isExtendedCompletion()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@NotNull final CompletionResultSet result = _result.caseInsensitive();
|
||||
final PsiElement e = parameters.getPosition();
|
||||
final Project project = e.getProject();
|
||||
@@ -94,14 +98,22 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
if (first == null) return;
|
||||
|
||||
final FileReferenceSet set = first.getFileReferenceSet();
|
||||
String prefix = set.getPathString().substring(0, parameters.getOffset() - set.getElement().getTextRange().getStartOffset() - set.getStartInElement());
|
||||
String prefix = set.getPathString()
|
||||
.substring(0, parameters.getOffset() - set.getElement().getTextRange().getStartOffset() - set.getStartInElement());
|
||||
final String textBeforePosition = e.getContainingFile().getText().substring(0, parameters.getOffset());
|
||||
if (!textBeforePosition.endsWith(prefix)) {
|
||||
final int len = textBeforePosition.length();
|
||||
final String fragment = len > 100 ? textBeforePosition.substring(len - 100) : textBeforePosition;
|
||||
throw new AssertionError("prefix should be some actual file string just before caret: " + prefix + "\n text=" + fragment + ";\npathString=" + set.getPathString() + ";\nelementText=" + e.getParent().getText());
|
||||
throw new AssertionError("prefix should be some actual file string just before caret: " +
|
||||
prefix +
|
||||
"\n text=" +
|
||||
fragment +
|
||||
";\npathString=" +
|
||||
set.getPathString() +
|
||||
";\nelementText=" +
|
||||
e.getParent().getText());
|
||||
}
|
||||
|
||||
|
||||
List<String> pathPrefixParts = null;
|
||||
int lastSlashIndex;
|
||||
if ((lastSlashIndex = prefix.lastIndexOf('/')) != -1) {
|
||||
@@ -141,7 +153,8 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
final VirtualFile virtualFile = file.getVirtualFile();
|
||||
if (virtualFile != null && virtualFile.isValid() && virtualFile != contextFile) {
|
||||
if (contextHelper.isMine(project, virtualFile)) {
|
||||
if (pathPrefixParts == null || fileMatchesPathPrefix(contextHelper.getPsiFileSystemItem(project, virtualFile), pathPrefixParts)) {
|
||||
if (pathPrefixParts == null ||
|
||||
fileMatchesPathPrefix(contextHelper.getPsiFileSystemItem(project, virtualFile), pathPrefixParts)) {
|
||||
__result.addElement(new FilePathLookupItem(file, contextHelper));
|
||||
}
|
||||
}
|
||||
@@ -163,7 +176,9 @@ public class FilePathCompletionContributor extends CompletionContributor {
|
||||
if (fileReferencePair.getSecond()) result.stopHere();
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
extend(CompletionType.CLASS_NAME, psiElement(), provider);
|
||||
extend(CompletionType.BASIC, psiElement(), provider);
|
||||
}
|
||||
|
||||
private static boolean filenameMatchesPrefixOrType(final String fileName, final String prefix, final FileType[] suitableFileTypes, final int invocationCount) {
|
||||
|
||||
+18
-13
@@ -260,19 +260,8 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
|
||||
// class name stuff
|
||||
|
||||
extend(CompletionType.CLASS_NAME, psiElement().withParent(GrReferenceElement.class), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters parameters,
|
||||
ProcessingContext context,
|
||||
@NotNull final CompletionResultSet result) {
|
||||
final PsiElement position = parameters.getPosition();
|
||||
if (((GrReferenceElement)position.getParent()).getQualifier() != null) return;
|
||||
|
||||
if (StringUtil.isEmpty(result.getPrefixMatcher().getPrefix())) return;
|
||||
|
||||
completeStaticMembers(parameters).processStaticMethodsGlobally(result);
|
||||
}
|
||||
});
|
||||
extend(CompletionType.CLASS_NAME, psiElement().withParent(GrReferenceElement.class), new GlobalStaticMembersProvider());
|
||||
extend(CompletionType.BASIC, psiElement().withParent(GrReferenceElement.class), new GlobalStaticMembersProvider());
|
||||
|
||||
extend(CompletionType.CLASS_NAME, psiElement(), new CompletionProvider<CompletionParameters>() {
|
||||
@Override
|
||||
@@ -784,4 +773,20 @@ public class GroovyCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class GlobalStaticMembersProvider extends CompletionProvider<CompletionParameters> {
|
||||
@Override
|
||||
protected void addCompletions(@NotNull CompletionParameters parameters,
|
||||
ProcessingContext context,
|
||||
@NotNull final CompletionResultSet result) {
|
||||
if (!parameters.isExtendedCompletion()) return;
|
||||
|
||||
final PsiElement position = parameters.getPosition();
|
||||
if (((GrReferenceElement)position.getParent()).getQualifier() != null) return;
|
||||
|
||||
if (StringUtil.isEmpty(result.getPrefixMatcher().getPrefix())) return;
|
||||
|
||||
completeStaticMembers(parameters).processStaticMethodsGlobally(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,7 +242,7 @@
|
||||
<completion.contributor language="any" implementationClass="com.intellij.codeInsight.completion.JavaClassNameCompletionContributor" id="javaClassName"
|
||||
order="last, before default"/>
|
||||
<completion.contributor language="JAVA" implementationClass="com.intellij.codeInsight.completion.JavaGlobalMemberNameCompletionContributor"
|
||||
id="javaGlobalMemberName" order="last, after javaClassName"/>
|
||||
id="javaGlobalMemberName"/>
|
||||
|
||||
<completion.contributor language="JAVA" implementationClass="com.intellij.codeInsight.completion.JavaDocCompletionContributor" id="javadoc"
|
||||
order="last, before javaLegacy"/>
|
||||
|
||||
@@ -128,7 +128,7 @@ public class XmlCompletionContributor extends CompletionContributor {
|
||||
|
||||
final PsiElement element = parameters.getPosition();
|
||||
|
||||
if (parameters.getCompletionType() == CompletionType.CLASS_NAME) {
|
||||
if (parameters.isExtendedCompletion()) {
|
||||
completeTagName(parameters, result);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user