Skip to content

Commit

Permalink
Make plugin hot-reloadable
Browse files Browse the repository at this point in the history
  • Loading branch information
leinardi committed Feb 26, 2022
1 parent 62c06bb commit 2aafc0a
Show file tree
Hide file tree
Showing 26 changed files with 49 additions and 69 deletions.
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,20 @@ intellij {

runIde {
systemProperties.put("idea.log.debug.categories", "#com.leinardi.pycharm.mypy")
// Log verbose information when dynamic plugin unloading fails
systemProperties.put("ide.plugins.snapshot.on.unload.fail", "true")
}

// Causes error popup when building while sandbox IDE is open. Disable in development
if (System.getenv('DEVELOP')) {
buildSearchableOptions.enabled = false
}


patchPluginXml {
version = project.property('version')
sinceBuild = project.property('sinceBuild')
untilBuild = project.property('untilBuild')
untilBuild = project.property('untilBuild')
pluginDescription = props.getProperty('plugin.Pylint-PyCharm.description')
changeNotes = getChangelogHtml()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class PylintAnnotator extends ExternalAnnotator<PylintAnnotator.State, Py
private static final String ERROR_MESSAGE_ID_SYNTAX_ERROR = "E0001";

private PylintPlugin plugin(final Project project) {
final PylintPlugin pylintPlugin = project.getComponent(PylintPlugin.class);
final PylintPlugin pylintPlugin = project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
26 changes: 3 additions & 23 deletions src/main/java/com/leinardi/pycharm/pylint/PylintPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.leinardi.pycharm.pylint;

import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.components.Service;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
Expand All @@ -43,12 +43,8 @@
/**
* Main class for the Pylint scanning plug-in.
*/
public final class PylintPlugin implements ProjectComponent {

/**
* The plugin ID. Caution: It must be identical to the String set in build.gradle at intellij.pluginName
*/
public static final String ID_PLUGIN = "Pylint-PyCharm";
@Service
public final class PylintPlugin {

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

Expand Down Expand Up @@ -94,22 +90,6 @@ public boolean isScanInProgress() {
}
}

@Override
public void projectOpened() {
LOG.debug("Project opened.");
}

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

@Override
@NotNull
public String getComponentName() {
return ID_PLUGIN;
}

public static void processErrorAndLog(@NotNull final String action, @NotNull final Throwable e) {
LOG.warn(action + " failed", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void update(final AnActionEvent event) {
return;
}

final PylintPlugin pylintPlugin = project.getComponent(PylintPlugin.class);
final PylintPlugin pylintPlugin = project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void actionPerformed(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void actionPerformed(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void actionPerformed(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean isSelected(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand All @@ -63,7 +63,7 @@ public void setSelected(final AnActionEvent event, final boolean selected) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean isSelected(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand All @@ -63,7 +63,7 @@ public void setSelected(final AnActionEvent event, final boolean selected) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean isSelected(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand All @@ -63,7 +63,7 @@ public void setSelected(final AnActionEvent event, final boolean selected) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean isSelected(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand All @@ -63,7 +63,7 @@ public void setSelected(final AnActionEvent event, final boolean selected) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean isSelected(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand All @@ -63,7 +63,7 @@ public void setSelected(final AnActionEvent event, final boolean selected) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void actionPerformed(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public final void actionPerformed(final AnActionEvent event) {
}

final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
project.getComponent(PylintPlugin.class)
project.getService(PylintPlugin.class)
.asyncScanFiles(VfUtil.filterOnlyPythonProjectFiles(project,
filesFor(changeListManager.getDefaultChangeList())));
} catch (Throwable e) {
Expand Down Expand Up @@ -85,7 +85,7 @@ public void update(final AnActionEvent event) {
return;
}

final PylintPlugin pylintPlugin = project.getComponent(PylintPlugin.class);
final PylintPlugin pylintPlugin = project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void actionPerformed(final AnActionEvent event) {

try {
final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand All @@ -59,7 +59,7 @@ public void actionPerformed(final AnActionEvent event) {

final VirtualFile selectedFile = getSelectedFile(project);
if (selectedFile != null) {
project.getComponent(PylintPlugin.class).asyncScanFiles(
project.getService(PylintPlugin.class).asyncScanFiles(
Collections.singletonList(selectedFile));
}

Expand Down Expand Up @@ -111,7 +111,7 @@ public void update(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public void run() {
filesToScan = VfUtil.flattenFiles(new VirtualFile[]{project.getBaseDir()});
filesToScan = VfUtil.filterOnlyPythonProjectFiles(project, filesToScan);

project.getComponent(PylintPlugin.class).asyncScanFiles(filesToScan);
project.getService(PylintPlugin.class).asyncScanFiles(filesToScan);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final void actionPerformed(final AnActionEvent event) {
}

final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
project.getComponent(PylintPlugin.class).asyncScanFiles(
project.getService(PylintPlugin.class).asyncScanFiles(
VfUtil.filterOnlyPythonProjectFiles(project, changeListManager.getAffectedFiles())
);
} catch (Throwable e) {
Expand All @@ -66,7 +66,7 @@ public void update(final AnActionEvent event) {
return;
}

final PylintPlugin pylintPlugin = project.getComponent(PylintPlugin.class);
final PylintPlugin pylintPlugin = project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public final void actionPerformed(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public final void update(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void actionPerformed(final AnActionEvent event) {
return;
}

final PylintPlugin pylintPlugin = project.getComponent(PylintPlugin.class);
final PylintPlugin pylintPlugin = project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down Expand Up @@ -89,7 +89,7 @@ public void update(final AnActionEvent event) {
return;
}

final PylintPlugin pylintPlugin = project.getComponent(PylintPlugin.class);
final PylintPlugin pylintPlugin = project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ScanSourceRootsAction implements Runnable {

@Override
public void run() {
project.getComponent(PylintPlugin.class)
project.getService(PylintPlugin.class)
.asyncScanFiles(VfUtil.filterOnlyPythonProjectFiles(project,
VfUtil.flattenFiles(sourceRoots)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public boolean isSelected(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand All @@ -63,7 +63,7 @@ public void setSelected(final AnActionEvent event, final boolean selected) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void actionPerformed(final AnActionEvent event) {
return;
}

final PylintPlugin pylintPlugin = project.getComponent(PylintPlugin.class);
final PylintPlugin pylintPlugin = project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void actionPerformed(final AnActionEvent event) {

try {
final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down Expand Up @@ -70,7 +70,7 @@ public void update(final AnActionEvent event) {
}

final PylintPlugin pylintPlugin
= project.getComponent(PylintPlugin.class);
= project.getService(PylintPlugin.class);
if (pylintPlugin == null) {
throw new IllegalStateException("Couldn't get pylint plugin");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public ReturnResult beforeCheckin(@Nullable final CommitExecutor executor,
return COMMIT;
}

final PylintPlugin plugin = project.getComponent(PylintPlugin.class);
final PylintPlugin plugin = project.getService(PylintPlugin.class);
if (plugin == null) {
LOG.warn("Could not get Pylint Plug-in, skipping");
return COMMIT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public PylintToolWindowPanel(final ToolWindow toolWindow, final Project project)
this.toolWindow = toolWindow;
this.project = project;

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

0 comments on commit 2aafc0a

Please sign in to comment.