mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-58092 SlowOperation: do not show superclasses in import suggestions (and remove parenthesis for functions)
(cherry picked from commit 04ee190f4491ce78e0a53622e75bcaeb41fa8370) IJ-MR-103609 GitOrigin-RevId: 0b3fc6a73b0f74021d4854fb2816b8de494806b8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
15ae6a7bf2
commit
5c58b4abdf
+4
-16
@@ -7,14 +7,15 @@ import com.intellij.openapi.util.NlsSafe;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.python.codeInsight.completion.PyCompletionUtilsKt;
|
||||
import com.jetbrains.python.psi.*;
|
||||
import com.jetbrains.python.psi.PyFromImportStatement;
|
||||
import com.jetbrains.python.psi.PyImportElement;
|
||||
import com.jetbrains.python.psi.PyReferenceExpression;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* An immutable holder of information for one auto-import candidate.
|
||||
@@ -127,24 +128,11 @@ public class ImportCandidateHolder implements Comparable<ImportCandidateHolder>
|
||||
@NotNull
|
||||
public @NlsSafe String getPresentableText() {
|
||||
PyImportElement importElement = getImportElement();
|
||||
PsiElement importable = getImportable();
|
||||
final StringBuilder sb = new StringBuilder(getQualifiedName(getImportableName(), myPath, importElement));
|
||||
PsiElement parent = null;
|
||||
if (importElement != null) {
|
||||
parent = importElement.getParent();
|
||||
}
|
||||
if (importable instanceof PyFunction) {
|
||||
sb.append("()");
|
||||
}
|
||||
else if (importable instanceof PyClass) {
|
||||
final List<String> supers = ContainerUtil.mapNotNull(((PyClass)importable).getSuperClasses(null),
|
||||
cls -> PyUtil.isObjectClass(cls) ? null : cls.getName());
|
||||
if (!supers.isEmpty()) {
|
||||
sb.append("(");
|
||||
StringUtil.join(supers, ", ", sb);
|
||||
sb.append(")");
|
||||
}
|
||||
}
|
||||
if (parent instanceof PyFromImportStatement fromImportStatement) {
|
||||
sb.append(" from ");
|
||||
sb.append(StringUtil.repeat(".", fromImportStatement.getRelativeLevel()));
|
||||
|
||||
@@ -82,7 +82,7 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
myFixture.copyDirectoryToProject("importFromModuleStar", "");
|
||||
myFixture.configureFromTempProjectFile("source.py");
|
||||
myFixture.checkHighlighting(true, false, false);
|
||||
final IntentionAction intentionAction = myFixture.findSingleIntention("Import 'target.xyzzy()'");
|
||||
final IntentionAction intentionAction = myFixture.findSingleIntention("Import 'target.xyzzy'");
|
||||
assertNotNull(intentionAction);
|
||||
myFixture.launchAction(intentionAction);
|
||||
myFixture.checkResultByFile("importFromModuleStar/source_after.py");
|
||||
@@ -110,7 +110,7 @@ public class PyQuickFixTest extends PyTestCase {
|
||||
settings.HIGHLIGHT_UNUSED_IMPORTS = false;
|
||||
try {
|
||||
doInspectionTest(new String[]{"AddToImportFromList.py", "AddToImportFromFoo.py"}, PyUnresolvedReferencesInspection.class,
|
||||
"Import 'add_to_import_test_unique_name() from AddToImportFromFoo'", true, true);
|
||||
"Import 'add_to_import_test_unique_name from AddToImportFromFoo'", true, true);
|
||||
}
|
||||
finally {
|
||||
settings.HIGHLIGHT_UNUSED_IMPORTS = oldHighlightUnused;
|
||||
|
||||
@@ -126,7 +126,7 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
|
||||
doMultiFileAutoImportTest("Import", fix -> {
|
||||
final List<ImportCandidateHolder> candidates = fix.getCandidates();
|
||||
final List<String> names = ContainerUtil.map(candidates, c -> c.getPresentableText());
|
||||
assertSameElements(names, "os.path.commonpath()");
|
||||
assertSameElements(names, "os.path.commonpath");
|
||||
return true;
|
||||
});
|
||||
};
|
||||
@@ -224,7 +224,7 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
|
||||
public void testExistingImportsAlwaysSuggestedFirstEvenIfNonProject() {
|
||||
doMultiFileAutoImportTest("Import", quickfix -> {
|
||||
final List<String> candidates = ContainerUtil.map(quickfix.getCandidates(), c -> c.getPresentableText());
|
||||
assertOrderedEquals(candidates, "datetime(date) from datetime", "mod.datetime");
|
||||
assertOrderedEquals(candidates, "datetime from datetime", "mod.datetime");
|
||||
return false;
|
||||
});
|
||||
}
|
||||
@@ -247,7 +247,7 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
|
||||
// PY-20100
|
||||
public void testAlwaysSplitFromImports() {
|
||||
getPythonCodeStyleSettings().OPTIMIZE_IMPORTS_ALWAYS_SPLIT_FROM_IMPORTS = true;
|
||||
doMultiFileAutoImportTest("Import 'mod.bar()'");
|
||||
doMultiFileAutoImportTest("Import 'mod.bar'");
|
||||
}
|
||||
|
||||
// PY-20976
|
||||
@@ -260,7 +260,7 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
|
||||
"os/path.py",
|
||||
"",
|
||||
(___) -> doTestProposedImportsOrdering(
|
||||
"path from sys", "first.path", "first.second.path()", "os.path", "first._third.path")
|
||||
"path from sys", "first.path", "first.second.path", "os.path", "first._third.path")
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -285,7 +285,7 @@ public class PyAddImportQuickFixTest extends PyQuickFixTestCase {
|
||||
|
||||
// PY-20976
|
||||
public void testOrderingSymbolBeforeModule() {
|
||||
doTestProposedImportsOrdering("first.module.foo()", "first.a.foo");
|
||||
doTestProposedImportsOrdering("first.module.foo", "first.a.foo");
|
||||
}
|
||||
|
||||
// PY-20976
|
||||
|
||||
Reference in New Issue
Block a user