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:
Elizaveta Shashkova
2023-02-24 19:30:54 +01:00
committed by intellij-monorepo-bot
parent 15ae6a7bf2
commit 5c58b4abdf
3 changed files with 11 additions and 23 deletions

View File

@@ -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()));