Add facet only to modules that contain Python files from change list

GitOrigin-RevId: 8dfe7051b43d04850e19e4cf12d849938ba63392
This commit is contained in:
Dmitry Trofimov
2019-09-19 20:29:50 +02:00
committed by intellij-monorepo-bot
parent bf6cbda222
commit 87a915e8a6
4 changed files with 25 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection;
import com.intellij.analysis.AnalysisScope;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.JavaSdk;
@@ -50,6 +51,6 @@ public class JavaCommandLineInspectionProjectConfigurator implements CommandLine
@Override
public void configureProject(@NotNull Project project) {
public void configureProject(@NotNull Project project, AnalysisScope scope) {
}
}

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInspection;
import com.intellij.analysis.AnalysisScope;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
@@ -20,5 +21,5 @@ public interface CommandLineInspectionProjectConfigurator {
*/
void configureEnvironment();
void configureProject(@NotNull Project project);
void configureProject(@NotNull Project project, AnalysisScope scope);
}

View File

@@ -252,7 +252,7 @@ public class InspectionApplication {
@NotNull List<? super Path> inspectionsResults) {
ProgressManager.getInstance().runProcess(() -> {
for (CommandLineInspectionProjectConfigurator configurator : CommandLineInspectionProjectConfigurator.EP_NAME.getIterable()) {
configurator.configureProject(project);
configurator.configureProject(project, scope);
}
if (!GlobalInspectionContextUtil.canRunInspections(project, false)) {

View File

@@ -1,18 +1,22 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.jetbrains.python.inspections;
import com.intellij.analysis.AnalysisScope;
import com.intellij.codeInspection.CommandLineInspectionProjectConfigurator;
import com.intellij.facet.FacetManager;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.fileTypes.FileTypeRegistry;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleUtilCore;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.ProjectJdkTable;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.util.ui.UIUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.jetbrains.python.PythonFileType;
import com.jetbrains.python.facet.PythonFacetType;
import com.jetbrains.python.sdk.*;
import com.jetbrains.python.sdk.PySdkExtKt;
import com.jetbrains.python.sdk.PythonSdkUpdater;
import com.jetbrains.python.sdk.PythonSdkUtil;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -65,14 +69,20 @@ public class PythonPluginCommandLineInspectionProjectConfigurator implements Com
}
@Override
public void configureProject(@NotNull Project project) {
public void configureProject(@NotNull Project project, AnalysisScope scope) {
List<Sdk> sdks = PythonSdkUtil.getAllSdks();
if (!sdks.isEmpty()) {
for (Module m : ModuleManager.getInstance(project).getModules()) {
PythonFacetType facetType = PythonFacetType.getInstance();
ApplicationManager.getApplication().runWriteAction(() -> {
FacetManager.getInstance(m).addFacet(facetType, facetType.getPresentableName(), null);
});
PythonFacetType facetType = PythonFacetType.getInstance();
for (VirtualFile f: scope.getFiles()) {
if (FileTypeRegistry.getInstance().isFileOfType(f, PythonFileType.INSTANCE)) {
Module m = ModuleUtilCore.findModuleForFile(f, project);
if (m != null && FacetManager.getInstance(m).getFacetByType(facetType.getId()) == null) {
ApplicationManager.getApplication().runWriteAction(() -> {
FacetManager.getInstance(m).addFacet(facetType, facetType.getPresentableName(), null);
});
}
}
}
}
}