- KT-1232 Do not place import with default imports in scope after completion
- Don't activate not-in-scope completion on typing by default
This commit is contained in:
@@ -146,10 +146,8 @@ public class JetCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
|
||||
if (PsiTreeUtil.getParentOfType(nameExpression, JetUserType.class) != null) {
|
||||
return true;
|
||||
return parameters.getInvocationCount() == 1;
|
||||
}
|
||||
|
||||
return parameters.getInvocationCount() == 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@ package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.StandardConfiguration;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaBridgeConfiguration;
|
||||
import org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -48,13 +50,10 @@ public class ImportClassHelper {
|
||||
importString = importString.substring((JavaDescriptorResolver.JAVA_ROOT + ".").length());
|
||||
}
|
||||
|
||||
// Check that import is useless
|
||||
if (QualifiedNamesUtil.isOneSegmentFQN(importString) ||
|
||||
JetPsiUtil.getFQName(file).equals(QualifiedNamesUtil.withoutLastSegment(importString))) {
|
||||
|
||||
if (isImportedByDefault(importString, JetPsiUtil.getFQName(file))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
List<JetImportDirective> importDirectives = file.getImportDirectives();
|
||||
|
||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(file.getProject(), importString);
|
||||
@@ -79,4 +78,26 @@ public class ImportClassHelper {
|
||||
firstDeclaration.getParent().addBefore(newDirective, firstDeclaration);
|
||||
}
|
||||
}
|
||||
|
||||
// Check that import is useless
|
||||
private static boolean isImportedByDefault(@NotNull String importString, @NotNull String filePackageFqn) {
|
||||
if (QualifiedNamesUtil.isOneSegmentFQN(importString) ||
|
||||
filePackageFqn.equals(QualifiedNamesUtil.withoutLastSegment(importString))) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
for (String defaultJetImport : StandardConfiguration.DEFAULT_JET_IMPORTS) {
|
||||
if (QualifiedNamesUtil.isImported(defaultJetImport, importString)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (String defaultJavaImport : JavaBridgeConfiguration.DEFAULT_JAVA_IMPORTS) {
|
||||
if (QualifiedNamesUtil.isImported(defaultJavaImport + ".*", importString)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
class A {}
|
||||
@@ -0,0 +1 @@
|
||||
class A {}
|
||||
@@ -8,7 +8,7 @@ import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
public class JetMultifileBasicCompletionTest extends JetCompletionMultiTestBase {
|
||||
|
||||
public void testTopLevelFunction() throws Exception {
|
||||
doFileTest();
|
||||
doFileTest(2);
|
||||
}
|
||||
|
||||
public void testExtensionFunction() throws Exception {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.jet.plugin.quickfix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightDaemonAnalyzerTestCase;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
|
||||
@@ -20,6 +21,17 @@ public class ImportClassHelperTest extends LightDaemonAnalyzerTestCase {
|
||||
checkResultByFile(getTestName(false) + ".kt.after");
|
||||
}
|
||||
|
||||
public void testNoDefaultImport() {
|
||||
configureByFile(getTestName(false) + ".kt");
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ImportClassHelper.addImportDirective("std.io.println", (JetFile) getFile());
|
||||
}
|
||||
});
|
||||
checkResultByFile(getTestName(false) + ".kt.after");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return PluginTestCaseBase.getTestDataPathBase() + "/quickfix/importHelper/";
|
||||
|
||||
Reference in New Issue
Block a user