Skip to content

Commit

Permalink
Added missing type "info" and autoscroll off by default
Browse files Browse the repository at this point in the history
  • Loading branch information
leinardi committed Sep 1, 2018
1 parent 7e32dcb commit 7a031bb
Show file tree
Hide file tree
Showing 17 changed files with 136 additions and 105 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
**[0.8.0] - 2018-09-01**
- New: Added missing type `info`
- New: Autoscroll to Source is disabled by default

**[0.7.1] - 2018-09-01**
- New: Project has moved to [https://github.com/leinardi/pylint-pycharm](https://github.com/leinardi/pylint-pycharm)

Expand Down
Binary file modified art/actions1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified art/actions2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified art/pylint-inspection-severity.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified art/pylint-pycharm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
version=0.7.1
version=0.8.0
ideaVersion=2016.1
sinceBuild=145.258
untilBuild=
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/com/leinardi/pycharm/pylint/PylintInspection.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@
import com.leinardi.pycharm.pylint.checker.ScanFiles;
import com.leinardi.pycharm.pylint.checker.ScannableFile;
import com.leinardi.pycharm.pylint.exception.PylintPluginParseException;
import com.leinardi.pycharm.pylint.ui.PylintInspectionPanel;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.JComponent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -50,8 +48,6 @@ public class PylintInspection extends LocalInspectionTool {
private static final Logger LOG = Logger.getInstance(PylintInspection.class);
private static final List<Problem> NO_PROBLEMS_FOUND = Collections.emptyList();

private final PylintInspectionPanel configPanel = new PylintInspectionPanel();

private PylintPlugin plugin(final Project project) {
final PylintPlugin pylintPlugin = project.getComponent(PylintPlugin.class);
if (pylintPlugin == null) {
Expand All @@ -60,12 +56,6 @@ private PylintPlugin plugin(final Project project) {
return pylintPlugin;
}

@Nullable
@Override
public JComponent createOptionsPanel() {
return configPanel;
}

@Override
public ProblemDescriptor[] checkFile(@NotNull final PsiFile psiFile,
@NotNull final InspectionManager manager,
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/com/leinardi/pycharm/pylint/actions/DisplayInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2018 Roberto Leinardi.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.leinardi.pycharm.pylint.actions;

import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.actionSystem.ToggleAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.leinardi.pycharm.pylint.PylintPlugin;
import com.leinardi.pycharm.pylint.toolwindow.PylintToolWindowPanel;

/**
* Action to toggle error display in tool window.
*/
public class DisplayInfo extends ToggleAction {

@Override
public boolean isSelected(final AnActionEvent event) {
final Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext());
if (project == null) {
return false;
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}

final ToolWindow toolWindow = ToolWindowManager.getInstance(
project).getToolWindow(PylintToolWindowPanel.ID_TOOLWINDOW);

final Content content = toolWindow.getContentManager().getContent(0);
if (content != null && content.getComponent() instanceof PylintToolWindowPanel) {
return ((PylintToolWindowPanel) content.getComponent()).isDisplayingInfo();
}

return false;
}

@Override
public void setSelected(final AnActionEvent event, final boolean selected) {
final Project project = PlatformDataKeys.PROJECT.getData(event.getDataContext());
if (project == null) {
return;
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}

final ToolWindow toolWindow = ToolWindowManager.getInstance(
project).getToolWindow(PylintToolWindowPanel.ID_TOOLWINDOW);

final Content content = toolWindow.getContentManager().getContent(0);
if (content != null && content.getComponent() instanceof PylintToolWindowPanel) {
final PylintToolWindowPanel panel = (PylintToolWindowPanel) content.getComponent();
panel.setDisplayingInfo(selected);
panel.filterDisplayedResults();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

package com.leinardi.pycharm.pylint.actions;

import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.leinardi.pycharm.pylint.PylintPlugin;
import com.leinardi.pycharm.pylint.util.VfUtil;
Expand All @@ -29,29 +27,16 @@
class ScanEverythingAction implements Runnable {

private final Project project;
private final Module module;

ScanEverythingAction(@NotNull final Project project) {
this.project = project;
this.module = null;
}

ScanEverythingAction(@NotNull final Module module) {
this.project = module.getProject();
this.module = module;
}

@Override
public void run() {
List<VirtualFile> filesToScan;
if (module != null) {
// all non-excluded files of a module
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
filesToScan = VfUtil.flattenFiles(moduleRootManager.getContentRoots());
} else {
// all non-excluded files of the project
filesToScan = VfUtil.flattenFiles(new VirtualFile[]{project.getBaseDir()});
}
// all non-excluded files of the project
filesToScan = VfUtil.flattenFiles(new VirtualFile[]{project.getBaseDir()});
filesToScan = VfUtil.filterOnlyPythonProjectFiles(project, filesToScan);

project.getComponent(PylintPlugin.class).asyncScanFiles(filesToScan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.nio.file.InvalidPathException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand Down Expand Up @@ -102,16 +104,21 @@ public void run() {
}

private String filenameFrom(final Issue issue) {
return withTrailingSeparator(baseDir) + issue.getPath();
String path = normalisePath(withTrailingSeparator(baseDir) + issue.getPath());
if (new File(path).exists()) {
return path;
} else {
return normalisePath(issue.getPath());
}
}

// private String normalisePath(String prefixedFileName) {
// try {
// return Paths.get(prefixedFileName).normalize().toString();
// } catch (InvalidPathException e) {
// return prefixedFileName; // cannot normalize
// }
// }
private String normalisePath(String prefixedFileName) {
try {
return Paths.get(prefixedFileName).normalize().toString();
} catch (InvalidPathException e) {
return prefixedFileName; // cannot normalize
}
}

private String withTrailingSeparator(final String path) {
if (path != null && !path.endsWith(File.separator)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public enum SeverityLevel {
@Json(name = "convention")
CONVENTION,
@Json(name = "refactor")
REFACTOR
REFACTOR,
@Json(name = "info")
INFO
}

Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,14 @@ public class PylintToolWindowPanel extends JPanel {
private boolean displayingWarnings = true;
private boolean displayingConvention = true;
private boolean displayingRefactor = true;
private boolean displayingInfo = true;

private JTree resultsTree;
private JToolBar progressPanel;
private JProgressBar progressBar;
private JLabel progressLabel;
private ResultTreeModel treeModel;
private boolean scrollToSource = true;
private boolean scrollToSource;

static {
try {
Expand Down Expand Up @@ -534,6 +535,9 @@ private SeverityLevel[] getDisplayedSeverities() {
if (displayingRefactor) {
severityLevels.add(SeverityLevel.REFACTOR);
}
if (displayingInfo) {
severityLevels.add(SeverityLevel.INFO);
}
return severityLevels.toArray(new SeverityLevel[0]);
}

Expand Down Expand Up @@ -592,4 +596,12 @@ public boolean isDisplayingRefactor() {
public void setDisplayingRefactor(final boolean displayingRefactor) {
this.displayingRefactor = displayingRefactor;
}

public boolean isDisplayingInfo() {
return displayingInfo;
}

public void setDisplayingInfo(boolean displayingInfo) {
this.displayingInfo = displayingInfo;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,13 @@ static String concatProblems(int[] problemCounts) {
refactorCount));
violations.append(", ");
}
int infoCount = problemCounts[SeverityLevel.INFO.ordinal()];
if (infoCount > 0) {
violations.append(StringUtil.pluralize(
PylintBundle.message("plugin.results.scan-results.info", infoCount),
infoCount));
violations.append(", ");
}
return new String(violations.deleteCharAt(violations.length() - 2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ private void updateIconsForProblem() {
icon = Icons.icon("/nodes/class.png");
} else if (SeverityLevel.REFACTOR.equals(severity)) {
icon = Icons.icon("/actions/forceRefresh.png");
} else {
} else if (SeverityLevel.INFO.equals(severity)) {
icon = Icons.icon("/general/information.png");
} else {
throw new IllegalStateException("Unknown severity level " + severity.name());
}
}

Expand Down

This file was deleted.

6 changes: 6 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@
description="Display Refactor results"
icon="/actions/forceRefresh.png"/>

<action id="PylintDisplayInfoAction"
class="com.leinardi.pycharm.pylint.actions.DisplayInfo"
text="Display Info"
description="Display info results"
icon="/general/information.png"/>

<separator/>

<action id="PylintClearAllAction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ plugin.results.scan-results.error={0} error
plugin.results.scan-results.warning={0} warning
plugin.results.scan-results.convention={0} convention
plugin.results.scan-results.refactor={0} refactor
plugin.results.scan-results.info={0} info
plugin.results.scan-file-result={0} : {1}
plugin.results.file-result={0} ({1}:{2}) [{3}]
plugin.results.unknown-source=unknown
Expand Down Expand Up @@ -64,7 +65,6 @@ config.pylint.path.failure.message=Failure: executable "{0}" not found
config.pylint.show-message-id=Show Pylint message ID in scan results
config.file.browse.text=Browse
config.file.browse.tooltip=Browse the file-system for Pylint executable
config.inspection.description=Please use the Pylint item in the Settings \
dialogue to configure the inspection
handler.before.checkin.checkbox=Scan with Pylint
handler.before.checkin.error.text={0} files contain problems
Expand Down

0 comments on commit 7a031bb

Please sign in to comment.