[python] packaging: add a quickfix to install all missing packages in a file (PY-71152)

GitOrigin-RevId: 6d87758b7551df057160cfb12420064baae13b21
This commit is contained in:
lada.gagina
2024-07-17 18:06:37 +02:00
committed by intellij-monorepo-bot
parent 19cf766f45
commit 0cd4aae5f5
4 changed files with 32 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package com.jetbrains.python.inspections.unresolvedReference;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.intellij.codeInsight.controlflow.ControlFlow;
import com.intellij.codeInsight.controlflow.ControlFlowUtil;
@@ -69,7 +70,7 @@ public abstract class PyUnresolvedReferencesVisitor extends PyInspectionVisitor
private final ImmutableSet<String> myIgnoredIdentifiers;
private final PyInspection myInspection;
private volatile Boolean myIsEnabled = null;
protected final Set<String> myUnresolvedNames = Collections.synchronizedSet(new HashSet<>());
protected PyUnresolvedReferencesVisitor(@Nullable ProblemsHolder holder,
List<String> ignoredIdentifiers,
@NotNull PyInspection inspection,
@@ -386,7 +387,12 @@ public abstract class PyUnresolvedReferencesVisitor extends PyInspectionVisitor
ContainerUtil.addAll(fixes, getImportStatementQuickFixes(element));
ContainerUtil.addAll(fixes, getAddIgnoredIdentifierQuickFixes(qualifiedNames));
ContainerUtil.addAll(fixes, getInstallPackageQuickFixes(node, reference, refName));
var installPackageQuickFixes = getInstallPackageQuickFixes(node, reference, refName);
if (Iterables.size(installPackageQuickFixes) > 0) {
ContainerUtil.addAll(fixes, getInstallPackageQuickFixes(node, reference, refName)); // todo lada может вообще сюда подсунуться и убрать отдельный метод?
myUnresolvedNames.add(refName);
ContainerUtil.addAll(fixes, getInstallAllPackagesQuickFixes());
}
if (reference instanceof PySubstitutionChunkReference) {
return;
@@ -893,6 +899,10 @@ public abstract class PyUnresolvedReferencesVisitor extends PyInspectionVisitor
return Collections.emptyList();
}
protected Iterable<LocalQuickFix> getInstallAllPackagesQuickFixes() {
return Collections.emptyList();
}
@Nullable
LocalQuickFix getCreateFunctionQuickFix(@NotNull PyReferenceExpression expr) {
PyCallExpression callExpression = PyCallExpressionNavigator.getPyCallExpressionByCallee(expr);