- Add sorting of completion elements into class completion
- Fix testNonStandardArray (it couldn't move selection to non-first element)
This commit is contained in:
@@ -32,6 +32,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
|||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
|
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
|
||||||
import org.jetbrains.jet.plugin.completion.handlers.JetJavaClassInsertHandler;
|
import org.jetbrains.jet.plugin.completion.handlers.JetJavaClassInsertHandler;
|
||||||
|
import org.jetbrains.jet.plugin.completion.weigher.JetCompletionSorting;
|
||||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||||
import org.jetbrains.jet.plugin.references.JetSimpleNameReference;
|
import org.jetbrains.jet.plugin.references.JetSimpleNameReference;
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ public class JetClassCompletionContributor extends CompletionContributor {
|
|||||||
@Override
|
@Override
|
||||||
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context,
|
protected void addCompletions(@NotNull CompletionParameters parameters, ProcessingContext context,
|
||||||
final @NotNull CompletionResultSet result) {
|
final @NotNull CompletionResultSet result) {
|
||||||
|
final CompletionResultSet jetResult = JetCompletionSorting.addJetSorting(parameters, result);
|
||||||
|
|
||||||
final PsiElement position = parameters.getPosition();
|
final PsiElement position = parameters.getPosition();
|
||||||
if (!(position.getContainingFile() instanceof JetFile)) {
|
if (!(position.getContainingFile() instanceof JetFile)) {
|
||||||
@@ -58,7 +60,7 @@ public class JetClassCompletionContributor extends CompletionContributor {
|
|||||||
addClasses(parameters, result, new Consumer<LookupElement>() {
|
addClasses(parameters, result, new Consumer<LookupElement>() {
|
||||||
@Override
|
@Override
|
||||||
public void consume(LookupElement lookupElement) {
|
public void consume(LookupElement lookupElement) {
|
||||||
result.addElement(lookupElement);
|
jetResult.addElement(lookupElement);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
result.stopHere();
|
result.stopHere();
|
||||||
|
|||||||
@@ -17,14 +17,13 @@
|
|||||||
package org.jetbrains.jet.completion.handlers;
|
package org.jetbrains.jet.completion.handlers;
|
||||||
|
|
||||||
import com.intellij.codeInsight.completion.CompletionType;
|
import com.intellij.codeInsight.completion.CompletionType;
|
||||||
import com.intellij.codeInsight.completion.JavaLookupElementBuilder;
|
|
||||||
import com.intellij.codeInsight.completion.LightCompletionTestCase;
|
import com.intellij.codeInsight.completion.LightCompletionTestCase;
|
||||||
import com.intellij.codeInsight.lookup.LookupElement;
|
import com.intellij.codeInsight.lookup.LookupElement;
|
||||||
import com.intellij.codeInsight.lookup.LookupElementBuilder;
|
import com.intellij.codeInsight.lookup.LookupElementPresentation;
|
||||||
|
import com.intellij.codeInsight.lookup.LookupManager;
|
||||||
|
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||||
import com.intellij.openapi.projectRoots.Sdk;
|
import com.intellij.openapi.projectRoots.Sdk;
|
||||||
import com.intellij.psi.JavaPsiFacade;
|
import junit.framework.Assert;
|
||||||
import com.intellij.psi.PsiClass;
|
|
||||||
import com.intellij.psi.search.GlobalSearchScope;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||||
|
|
||||||
@@ -36,14 +35,11 @@ import java.io.File;
|
|||||||
public class CompletionHandlerTest extends LightCompletionTestCase {
|
public class CompletionHandlerTest extends LightCompletionTestCase {
|
||||||
|
|
||||||
public void testClassCompletionImport() {
|
public void testClassCompletionImport() {
|
||||||
doTest(CompletionType.CLASS_NAME, 1, LookupElementBuilder.create("SortedSet"));
|
doTest(CompletionType.CLASS_NAME, 1, "SortedSet", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNonStandardArray() {
|
public void testNonStandardArray() {
|
||||||
PsiClass reflectArrayClass = JavaPsiFacade.getInstance(getProject()).findClass(
|
doTest(CompletionType.CLASS_NAME, 1, "Array", "java.lang.reflect");
|
||||||
"java.lang.reflect.Array", GlobalSearchScope.allScope(getProject()));
|
|
||||||
assert reflectArrayClass != null;
|
|
||||||
doTest(CompletionType.CLASS_NAME, 1, JavaLookupElementBuilder.forClass(reflectArrayClass));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testNoParamsFunction() {
|
public void testNoParamsFunction() {
|
||||||
@@ -77,26 +73,69 @@ public class CompletionHandlerTest extends LightCompletionTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void doTest() {
|
public void doTest() {
|
||||||
doTest(CompletionType.BASIC, 2, null);
|
doTest(CompletionType.BASIC, 2, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void doTest(CompletionType type, int time, @Nullable LookupElement completeItem) {
|
public void doTest(CompletionType type, int time, @Nullable String lookupString, @Nullable String tailText) {
|
||||||
try {
|
try {
|
||||||
configureByFileNoComplete(getBeforeFileName());
|
configureByFileNoComplete(getBeforeFileName());
|
||||||
setType(type);
|
setType(type);
|
||||||
|
|
||||||
complete(time);
|
complete(time);
|
||||||
|
|
||||||
if (completeItem != null) {
|
if (lookupString != null || tailText != null) {
|
||||||
selectItem(completeItem, '\t');
|
selectItem(getExistentLookupElement(lookupString, tailText), '\t');
|
||||||
}
|
}
|
||||||
|
|
||||||
checkResultByFile(getAfterFileName());
|
checkResultByFile(getAfterFileName());
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e) {
|
||||||
throw new AssertionError(e);
|
throw new AssertionError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LookupElement getExistentLookupElement(@Nullable String lookupString, @Nullable String tailText) {
|
||||||
|
final LookupImpl lookup = (LookupImpl) LookupManager.getInstance(getProject()).getActiveLookup();
|
||||||
|
LookupElement foundElement = null;
|
||||||
|
|
||||||
|
if (lookup != null) {
|
||||||
|
final LookupElementPresentation presentation = new LookupElementPresentation();
|
||||||
|
|
||||||
|
for (LookupElement lookupElement : lookup.getItems()) {
|
||||||
|
boolean lookupOk;
|
||||||
|
|
||||||
|
if (lookupString != null) {
|
||||||
|
lookupOk = (lookupElement.getLookupString().contains(lookupString));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lookupOk = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean tailOk;
|
||||||
|
|
||||||
|
if (tailText != null) {
|
||||||
|
lookupElement.renderElement(presentation);
|
||||||
|
String itemTailText = presentation.getTailText();
|
||||||
|
tailOk = itemTailText != null && itemTailText.contains(tailText);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
tailOk = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (lookupOk && tailOk) {
|
||||||
|
if (foundElement != null) {
|
||||||
|
Assert.fail("Several elements satisfy to completion restrictions");
|
||||||
|
}
|
||||||
|
foundElement = lookupElement;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertNotNull("No element found for given constraints",foundElement);
|
||||||
|
return foundElement;
|
||||||
|
}
|
||||||
|
|
||||||
protected String getBeforeFileName() {
|
protected String getBeforeFileName() {
|
||||||
return getTestName(false) + ".kt";
|
return getTestName(false) + ".kt";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user