Skip to content

Commit

Permalink
Removed commented code
Browse files Browse the repository at this point in the history
  • Loading branch information
leinardi committed Aug 31, 2018
1 parent 38d5faa commit 0d8cd78
Show file tree
Hide file tree
Showing 24 changed files with 55 additions and 522 deletions.
52 changes: 3 additions & 49 deletions src/main/java/com/leinardi/pycharm/pylint/PylintConfigurable.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,17 @@
public class PylintConfigurable implements Configurable {
private static final Logger LOG = Logger.getInstance(PylintConfigurable.class);

private final Project project;

private final PylintConfigPanel configPanel;
private final PylintConfigService pylintConfigService;
// private final PylintProjectService pylintProjectService;
// private final PluginConfigurationManager pluginConfigurationManager;

public PylintConfigurable(@NotNull final Project project/*,
@NotNull final PylintProjectService pylintProjectService,
@NotNull final PluginConfigurationManager pluginConfigurationManager*/) {
this(project, new PylintConfigPanel(project/*, pylintProjectService*/)/*,
pylintProjectService, pluginConfigurationManager*/);
public PylintConfigurable(@NotNull final Project project) {
this(project, new PylintConfigPanel(project));
}

PylintConfigurable(@NotNull final Project project,
@NotNull final PylintConfigPanel configPanel/*,
@NotNull final PylintProjectService pylintProjectService,
@NotNull final PluginConfigurationManager pluginConfigurationManager*/) {
this.project = project;
@NotNull final PylintConfigPanel configPanel) {
this.configPanel = configPanel;
pylintConfigService = PylintConfigService.getInstance(project);
// this.pylintProjectService = pylintProjectService;
// this.pluginConfigurationManager = pluginConfigurationManager;
}

@Override
Expand All @@ -74,12 +62,6 @@ public JComponent createComponent() {

@Override
public boolean isModified() {
// final PluginConfiguration oldConfig = pluginConfigurationManager.getCurrent();
// final PluginConfiguration newConfig = PluginConfigurationBuilder
// .from(configPanel.getPluginConfiguration())
// .withScanBeforeCheckin(oldConfig.isScanBeforeCheckin())
// .build();
//
boolean result = !configPanel.getPathToPylint().equals(pylintConfigService.getPathToPylint());
if (LOG.isDebugEnabled()) {
LOG.debug("Has config changed? " + result);
Expand All @@ -89,37 +71,9 @@ public boolean isModified() {

@Override
public void apply() {
// final PluginConfiguration newConfig = PluginConfigurationBuilder.from(configPanel
// .getPluginConfiguration())
// .withScanBeforeCheckin(pluginConfigurationManager.getCurrent().isScanBeforeCheckin())
// .build();
// pluginConfigurationManager.setCurrent(newConfig, true);
//
// activateCurrentPylintVersion(newConfig.getPylintVersion(), newConfig.getThirdPartyClasspath());
// if (!newConfig.isCopyLibs()) {
// new TempDirProvider().deleteCopiedLibrariesDir(project);
// }
pylintConfigService.setPathToPylint(configPanel.getPathToPylint());
}

// private void activateCurrentPylintVersion(final String pylintVersion,
// final List<String> thirdPartyClasspath) {
// // Invalidate cache *before* activating the new Pylint version
// getCheckerFactoryCache().invalidate();
//
// pylintProjectService.activatePylintVersion(pylintVersion, thirdPartyClasspath);
// }
//
// private CheckerFactoryCache getCheckerFactoryCache() {
// return ServiceManager.getService(project, CheckerFactoryCache.class);
// }
//
// public void reset() {
// final PluginConfiguration pluginConfig = pluginConfigurationManager.getCurrent();
// configPanel.showPluginConfiguration(pluginConfig);
//
// activateCurrentPylintVersion(pluginConfig.getPylintVersion(), pluginConfig.getThirdPartyClasspath());
// }
@Override
public void disposeUIResources() {
// do nothing
Expand Down
50 changes: 3 additions & 47 deletions src/main/java/com/leinardi/pycharm/pylint/PylintInspection.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import com.intellij.codeInspection.LocalInspectionTool;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleUtil;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -72,16 +70,10 @@ public JComponent createOptionsPanel() {
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile,
@NotNull final InspectionManager manager,
final boolean isOnTheFly) {
// final Module module = moduleOf(psiFile);
return asProblemDescriptors(asyncResultOf(() -> inspectFile(psiFile, /*module, */manager), NO_PROBLEMS_FOUND),
return asProblemDescriptors(asyncResultOf(() -> inspectFile(psiFile, manager), NO_PROBLEMS_FOUND),
manager);
}

@Nullable
private Module moduleOf(@NotNull final PsiFile psiFile) {
return ModuleUtil.findModuleForPsiElement(psiFile);
}

@Nullable
public List<Problem> inspectFile(@NotNull final PsiFile psiFile,
// @Nullable final Module module,
Expand All @@ -90,15 +82,9 @@ public List<Problem> inspectFile(@NotNull final PsiFile psiFile,

final PylintPlugin plugin = plugin(manager.getProject());

// ConfigurationLocation configurationLocation = null;
final List<ScannableFile> scannableFiles = new ArrayList<>();
try {
// configurationLocation = plugin.getConfigurationLocation(module, null);
// if (configurationLocation == null || configurationLocation.isBlacklisted()) {
// return NO_PROBLEMS_FOUND;
// }

scannableFiles.addAll(ScannableFile.createAndValidate(singletonList(psiFile), plugin/*, module*/));
scannableFiles.addAll(ScannableFile.createAndValidate(singletonList(psiFile), plugin));
ScanFiles scanFiles = new ScanFiles(plugin, Collections.singletonList(psiFile.getVirtualFile()));
Map<PsiFile, List<Problem>> map = scanFiles.call();
if (map.isEmpty()) {
Expand All @@ -115,51 +101,26 @@ public List<Problem> inspectFile(@NotNull final PsiFile psiFile,
return NO_PROBLEMS_FOUND;

} catch (Throwable e) {
handlePluginException(e, psiFile, /*plugin, configurationLocation,*/ manager.getProject());
handlePluginException(e, psiFile, manager.getProject());
return NO_PROBLEMS_FOUND;

} finally {
scannableFiles.forEach(ScannableFile::deleteIfRequired);
}
}

// private List<Problem> dropIgnoredProblems(final List<Problem> problems) {
// return problems.stream()
// .filter(problem -> problem.severityLevel() != SeverityLevel.Ignore)
// .collect(toList());
// }

private void handlePluginException(final Throwable e,
final @NotNull PsiFile psiFile,
// final PylintPlugin plugin,
// final ConfigurationLocation
// configurationLocation,
final @NotNull Project project) {
// if (e.getCause() != null && e.getCause() instanceof FileNotFoundException) {
// disableActiveConfiguration(plugin, project);
// } else
if (e.getCause() != null && e.getCause() instanceof IOException) {
showWarning(project, message("pylint.file-io-failed"));
// blacklist(configurationLocation);

} else {
LOG.warn("Pylint threw an exception when scanning: " + psiFile.getName(), e);
showException(project, e);
// blacklist(configurationLocation);
}
}

// private void disableActiveConfiguration(final PylintPlugin plugin, final Project project) {
// plugin.configurationManager().disableActiveConfiguration();
// showWarning(project, message("pylint.configuration-disabled.file-not-found"));
// }

// private void blacklist(final ConfigurationLocation configurationLocation) {
// if (configurationLocation != null) {
// configurationLocation.blacklist();
// }
// }

@NotNull
private ProblemDescriptor[] asProblemDescriptors(final List<Problem> results, final InspectionManager manager) {
return ofNullable(results)
Expand All @@ -168,9 +129,4 @@ private ProblemDescriptor[] asProblemDescriptors(final List<Problem> results, fi
.toArray(ProblemDescriptor[]::new))
.orElseGet(() -> ProblemDescriptor.EMPTY_ARRAY);
}

// private CheckerFactory checkerFactory(final Project project) {
// return ServiceManager.getService(project, CheckerFactory.class);
// }

}
75 changes: 4 additions & 71 deletions src/main/java/com/leinardi/pycharm/pylint/PylintPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@

package com.leinardi.pycharm.pylint;

import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
Expand Down Expand Up @@ -53,23 +50,18 @@ public final class PylintPlugin implements ProjectComponent {
*/
public static final String ID_PLUGIN = "Pylint-PyCharm";

// public static final String ID_MODULE_PLUGIN = "Pylint-PyCharm-Module";

private static final Logger LOG = com.intellij.openapi.diagnostic.Logger.getInstance(PylintPlugin.class);

private final Set<Future<?>> checksInProgress = new HashSet<>();
private final Project project;
// private final PluginConfigurationManager configurationManager;

/**
* Construct a plug-in instance for the given project.
*
* @param project the current project.
*/
public PylintPlugin(@NotNull final Project project
/*, @NotNull final PluginConfigurationManager configurationManager*/) {
public PylintPlugin(@NotNull final Project project) {
this.project = project;
// this.configurationManager = configurationManager;

LOG.info("Pylint Plugin loaded with project base dir: \"" + getProjectPath() + "\"");

Expand All @@ -89,15 +81,6 @@ private File getProjectPath() {
return new File(baseDir.getPath());
}

// /**
// * Get the plugin configuration.
// *
// * @return the plug-in configuration.
// */
// public PluginConfigurationManager configurationManager() {
// return configurationManager;
// }

/**
* Is a scan in progress?
* <p>
Expand All @@ -114,41 +97,13 @@ public boolean isScanInProgress() {
@Override
public void projectOpened() {
LOG.debug("Project opened.");
// notifyUserIfPluginUpdated();
}

// private void notifyUserIfPluginUpdated() {
// if (!Objects.equals(currentPluginVersion(), lastActivePluginVersion())) {
// Notifications.showInfo(project, message("plugin.update", currentPluginVersion()));
// configurationManager.setCurrent(PluginConfigurationBuilder.from(configurationManager.getCurrent())
// .withLastActivePluginVersion(currentPluginVersion())
// .build(), false);
// }
// }

// private String lastActivePluginVersion() {
// return configurationManager.getCurrent().getLastActivePluginVersion();
// }

public static String currentPluginVersion() {
final IdeaPluginDescriptor plugin = PluginManager.getPlugin(PluginId.getId(ID_PLUGIN));
if (plugin != null) {
return plugin.getVersion();
}
return "unknown";
}

@Override
public void projectClosed() {
LOG.debug("Project closed; invalidating checkers.");

// invalidateCheckerCache();
}

// private void invalidateCheckerCache() {
// ServiceManager.getService(project, CheckerFactoryCache.class).invalidate();
// }

@Override
@NotNull
public String getComponentName() {
Expand Down Expand Up @@ -194,16 +149,15 @@ public <T> void checkComplete(final Future<T> task) {
}

@SuppressWarnings("FutureReturnValueIgnored")
public void asyncScanFiles(final List<VirtualFile> files/*, final ConfigurationLocation
overrideConfigLocation*/) {
public void asyncScanFiles(final List<VirtualFile> files) {
LOG.info("Scanning current file(s).");

if (files == null || files.isEmpty()) {
LOG.debug("No files provided.");
return;
}

final ScanFiles checkFiles = new ScanFiles(this, files/*, overrideConfigLocation*/);
final ScanFiles checkFiles = new ScanFiles(this, files);
checkFiles.addListener(new UiFeedbackScannerListener(this));
runAsyncCheck(checkFiles);
}
Expand All @@ -214,7 +168,7 @@ public Map<PsiFile, List<Problem>> scanFiles(@NotNull final List<VirtualFile> fi
}

try {
return whenFinished(runAsyncCheck(new ScanFiles(this, files/*, null*/))).get();
return whenFinished(runAsyncCheck(new ScanFiles(this, files))).get();
} catch (final Throwable e) {
LOG.warn("ERROR scanning files", e);
return Collections.emptyMap();
Expand All @@ -228,27 +182,6 @@ private Future<Map<PsiFile, List<Problem>>> runAsyncCheck(final ScanFiles checke
return checkFilesFuture;
}

// public ConfigurationLocation getConfigurationLocation(@Nullable final Module module, @Nullable final
// ConfigurationLocation override) {
// if (override != null) {
// return override;
// }
//
// if (module != null) {
// final PylintModuleConfiguration moduleConfiguration = ModuleServiceManager.getService(module,
// PylintModuleConfiguration.class);
// if (moduleConfiguration == null) {
// throw new IllegalStateException("Couldn't get pylint module configuration");
// }
//
// if (moduleConfiguration.isExcluded()) {
// return null;
// }
// return moduleConfiguration.getActiveConfiguration();
// }
// return configurationManager().getCurrent().getActiveLocation();
// }

private class ScanCompletionTracker implements ScannerListener {

private final Future<Map<PsiFile, List<Problem>>> future;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,11 @@ protected void setProgressText(final ToolWindow toolWindow, final String progres
}
}

// protected ConfigurationLocation getSelectedOverride(final ToolWindow toolWindow) {
// final Content content = toolWindow.getContentManager().getContent(0);
// // the content instance will be a JLabel while the component initialises
// if (content != null && content.getComponent() instanceof PylintToolWindowPanel) {
// return ((PylintToolWindowPanel) content.getComponent()).getSelectedOverride();
// }
// return null;
// }

protected Optional<Project> project(@NotNull final AnActionEvent event) {
return ofNullable(PROJECT.getData(event.getDataContext()));
}

protected boolean containsAtLeastOneFile(@NotNull final VirtualFile... files) {
boolean containsAtLeastOneFile(@NotNull final VirtualFile... files) {
boolean result = false;
for (VirtualFile file : files) {
if ((file.isDirectory() && containsAtLeastOneFile(file.getChildren())) || (!file.isDirectory() && file
Expand Down
Loading

0 comments on commit 0d8cd78

Please sign in to comment.