#KT-1598 fixed Wrong completion after "as" in imports
This commit is contained in:
@@ -66,9 +66,15 @@ public class JetCompletionContributor extends CompletionContributor {
|
||||
JetSimpleNameReference jetReference = getJetReference(parameters);
|
||||
if (jetReference != null) {
|
||||
|
||||
// Prevent from adding reference variants from standard reference contributor
|
||||
result.stopHere();
|
||||
|
||||
if (isOnlyKeywordCompletion(position)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (shouldRunTypeCompletionOnly(position, jetReference)) {
|
||||
addClasses(parameters, result);
|
||||
result.stopHere();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -76,9 +82,6 @@ public class JetCompletionContributor extends CompletionContributor {
|
||||
addReferenceVariant(result, variant, positions);
|
||||
}
|
||||
|
||||
// Prevent from adding reference variants from standard reference contributor
|
||||
result.stopHere();
|
||||
|
||||
String prefix = result.getPrefixMatcher().getPrefix();
|
||||
|
||||
// Try to avoid computing not-imported descriptors for empty prefix
|
||||
@@ -105,6 +108,10 @@ public class JetCompletionContributor extends CompletionContributor {
|
||||
});
|
||||
}
|
||||
|
||||
private static boolean isOnlyKeywordCompletion(PsiElement position) {
|
||||
return PsiTreeUtil.getParentOfType(position, JetModifierList.class) != null;
|
||||
}
|
||||
|
||||
private static void addJetExtensions(JetSimpleNameExpression expression, CompletionResultSet result, PsiElement position) {
|
||||
final PrefixMatcher prefixMatcher = result.getPrefixMatcher();
|
||||
JetShortNamesCache namesCache = JetCacheManager.getInstance(position.getProject()).getNamesCache();
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
import kotlin.util <caret>// Comment to prevent for removing trailing spaces
|
||||
@@ -0,0 +1 @@
|
||||
import kotlin.util as // Comment to prevent for removing trailing spaces
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
import java.util.AbstractSet as Hello
|
||||
|
||||
<caret>// Comment to prevent for removing trailing spaces
|
||||
@@ -0,0 +1,5 @@
|
||||
package test
|
||||
|
||||
import java.util.AbstractSet as Hello
|
||||
|
||||
public // Comment to prevent for removing trailing spaces
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright 2010-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.completion.confidence;
|
||||
|
||||
import com.intellij.codeInsight.completion.LightCompletionTestCase;
|
||||
import com.intellij.openapi.projectRoots.JavaSdk;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import org.apache.commons.lang.SystemUtils;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author Nikolay Krasko
|
||||
*/
|
||||
public class JetConfidenceTest extends LightCompletionTestCase {
|
||||
|
||||
public void testImportAsConfidence() {
|
||||
doTest("as");
|
||||
}
|
||||
|
||||
public void testInModifierList() {
|
||||
doTest("pub");
|
||||
}
|
||||
|
||||
protected void doTest(String completionActivateType) {
|
||||
configureByFile(getBeforeFileName());
|
||||
type(completionActivateType + " ");
|
||||
checkResultByFile(getAfterFileName());
|
||||
}
|
||||
|
||||
protected String getBeforeFileName() {
|
||||
return getTestName(false) + ".kt";
|
||||
}
|
||||
|
||||
protected String getAfterFileName() {
|
||||
return getTestName(false) + ".kt.after";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/completion/confidence/").getPath() + File.separator;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Sdk getProjectJDK() {
|
||||
return JavaSdk.getInstance().createJdk("JDK", SystemUtils.getJavaHome().getAbsolutePath());
|
||||
}
|
||||
}
|
||||
@@ -51,9 +51,9 @@ public class CompletionHandlerTest extends LightCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testSingleBrackets() {
|
||||
configureByFile("SingleBrackets.kt");
|
||||
configureByFile(getBeforeFileName());
|
||||
type('(');
|
||||
checkResultByFile("SingleBrackets.kt.after");
|
||||
checkResultByFile(getAfterFileName());
|
||||
}
|
||||
|
||||
public void testExistingSingleBrackets() {
|
||||
@@ -69,9 +69,8 @@ public class CompletionHandlerTest extends LightCompletionTestCase {
|
||||
}
|
||||
|
||||
public void doTest(CompletionType type, int time, @Nullable String completeItem) {
|
||||
String fileName = getTestName(false);
|
||||
try {
|
||||
configureByFileNoComplete(fileName + ".kt");
|
||||
configureByFileNoComplete(getBeforeFileName());
|
||||
setType(type);
|
||||
|
||||
complete(time);
|
||||
@@ -80,12 +79,20 @@ public class CompletionHandlerTest extends LightCompletionTestCase {
|
||||
selectItem(LookupElementBuilder.create(completeItem), '\t');
|
||||
}
|
||||
|
||||
checkResultByFile(fileName + ".kt.after");
|
||||
checkResultByFile(getAfterFileName());
|
||||
} catch (Exception e) {
|
||||
throw new AssertionError(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected String getBeforeFileName() {
|
||||
return getTestName(false) + ".kt";
|
||||
}
|
||||
|
||||
protected String getAfterFileName() {
|
||||
return getTestName(false) + ".kt.after";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return new File(PluginTestCaseBase.getTestDataPathBase(), "/completion/handlers/").getPath() + File.separator;
|
||||
|
||||
Reference in New Issue
Block a user