mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Don't report unresolved references and unused imports during skeletons generation
This commit is contained in:
@@ -61,6 +61,7 @@ import com.jetbrains.python.psi.resolve.QualifiedNameFinder;
|
||||
import com.jetbrains.python.psi.resolve.RatedResolveResult;
|
||||
import com.jetbrains.python.psi.types.*;
|
||||
import com.jetbrains.python.sdk.PythonSdkType;
|
||||
import com.jetbrains.python.sdk.skeletons.PySkeletonRefresher;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -126,18 +127,20 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
private Set<PsiElement> myUsedImports = Collections.synchronizedSet(new HashSet<PsiElement>());
|
||||
private Set<NameDefiner> myAllImports = Collections.synchronizedSet(new HashSet<NameDefiner>());
|
||||
private final ImmutableSet<String> myIgnoredIdentifiers;
|
||||
private volatile Boolean myHasSdk = null;
|
||||
private volatile Boolean myIsEnabled = null;
|
||||
|
||||
public Visitor(@Nullable ProblemsHolder holder, @NotNull LocalInspectionToolSession session, List<String> ignoredIdentifiers) {
|
||||
super(holder, session);
|
||||
myIgnoredIdentifiers = ImmutableSet.copyOf(ignoredIdentifiers);
|
||||
}
|
||||
|
||||
public boolean hasSdk(@NotNull PsiElement anchor) {
|
||||
if (myHasSdk == null) {
|
||||
myHasSdk = PlatformUtils.isPyCharm() && PythonSdkType.getSdk(anchor) != null;
|
||||
public boolean isEnabled(@NotNull PsiElement anchor) {
|
||||
if (myIsEnabled == null) {
|
||||
final boolean isPyCharm = PlatformUtils.isPyCharm();
|
||||
myIsEnabled = (isPyCharm && PythonSdkType.getSdk(anchor) != null || !isPyCharm) &&
|
||||
!PySkeletonRefresher.isGeneratingSkeletons(anchor.getProject());
|
||||
}
|
||||
return myHasSdk;
|
||||
return myIsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -183,7 +186,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
public void visitPyImportElement(PyImportElement node) {
|
||||
super.visitPyImportElement(node);
|
||||
final PyFromImportStatement fromImport = PsiTreeUtil.getParentOfType(node, PyFromImportStatement.class);
|
||||
if (hasSdk(node) && (fromImport == null || !fromImport.isFromFuture())) {
|
||||
if (isEnabled(node) && (fromImport == null || !fromImport.isFromFuture())) {
|
||||
myAllImports.add(node);
|
||||
}
|
||||
}
|
||||
@@ -191,7 +194,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
@Override
|
||||
public void visitPyStarImportElement(PyStarImportElement node) {
|
||||
super.visitPyStarImportElement(node);
|
||||
if (hasSdk(node)) {
|
||||
if (isEnabled(node)) {
|
||||
myAllImports.add(node);
|
||||
}
|
||||
}
|
||||
@@ -309,7 +312,7 @@ public class PyUnresolvedReferencesInspection extends PyInspection {
|
||||
}
|
||||
|
||||
private void processReference(PyElement node, @Nullable PsiReference reference) {
|
||||
if (!hasSdk(node) || reference == null || reference.isSoft()) {
|
||||
if (!isEnabled(node) || reference == null || reference.isSoft()) {
|
||||
return;
|
||||
}
|
||||
HighlightSeverity severity = HighlightSeverity.ERROR;
|
||||
|
||||
@@ -29,6 +29,7 @@ import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.roots.OrderRootType;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
@@ -91,6 +92,8 @@ public class PySkeletonRefresher {
|
||||
private static final Pattern FROM_LINE_V2 = Pattern.compile("# from (.*)$");
|
||||
private static final Pattern BY_LINE_V2 = Pattern.compile("# by generator (.*)$");
|
||||
|
||||
private static final Key<Boolean> GENERATING_SKELETONS = Key.create("PySkeletonRefresher.generatingSkeletons");
|
||||
|
||||
private String myExtraSyspath;
|
||||
private VirtualFile myPregeneratedSkeletons;
|
||||
private int myGeneratorVersion;
|
||||
@@ -103,6 +106,15 @@ public class PySkeletonRefresher {
|
||||
refreshSkeletonsOfSdk(project, null, PythonSdkType.findSkeletonsPath(sdk), new Ref<Boolean>(false), sdk);
|
||||
}
|
||||
|
||||
public static boolean isGeneratingSkeletons(@NotNull Project project) {
|
||||
final Boolean value = project.getUserData(GENERATING_SKELETONS);
|
||||
return value != null && value;
|
||||
}
|
||||
|
||||
private static void setGeneratingSkeletons(@NotNull Project project, boolean value) {
|
||||
project.putUserData(GENERATING_SKELETONS, value);
|
||||
}
|
||||
|
||||
public static void refreshSkeletonsOfSdk(@Nullable Project project,
|
||||
Component ownerComponent,
|
||||
String skeletonsPath,
|
||||
@@ -120,15 +132,26 @@ public class PySkeletonRefresher {
|
||||
LOG.info("Refreshing skeletons for " + homePath);
|
||||
SkeletonVersionChecker checker = new SkeletonVersionChecker(0); // this default version won't be used
|
||||
final PySkeletonRefresher refresher = new PySkeletonRefresher(project, ownerComponent, sdk, skeletonsPath, indicator);
|
||||
List<String> sdkErrors = refresher.regenerateSkeletons(checker, migrationFlag);
|
||||
if (sdkErrors.size() > 0) {
|
||||
String sdkName = sdk.getName();
|
||||
List<String> knownErrors = errors.get(sdkName);
|
||||
if (knownErrors == null) {
|
||||
errors.put(sdkName, sdkErrors);
|
||||
|
||||
if (project != null) {
|
||||
setGeneratingSkeletons(project, true);
|
||||
}
|
||||
try {
|
||||
List<String> sdkErrors = refresher.regenerateSkeletons(checker, migrationFlag);
|
||||
if (sdkErrors.size() > 0) {
|
||||
String sdkName = sdk.getName();
|
||||
List<String> knownErrors = errors.get(sdkName);
|
||||
if (knownErrors == null) {
|
||||
errors.put(sdkName, sdkErrors);
|
||||
}
|
||||
else {
|
||||
knownErrors.addAll(sdkErrors);
|
||||
}
|
||||
}
|
||||
else {
|
||||
knownErrors.addAll(sdkErrors);
|
||||
}
|
||||
finally {
|
||||
if (project != null) {
|
||||
setGeneratingSkeletons(project, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user