diff --git a/.idea/misc.xml b/.idea/misc.xml index f91b516..24fff94 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,3 +1,4 @@ + diff --git a/README.md b/README.md index d2f8704..ee1866f 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,9 @@

InlineProblems

-Plugin to show problems like errors and warnings inside the text editor (inline) for IDEs based on the IntelliJ Platform, inspired by Error Lens and InlineError +Plugin to show problems like errors and warnings inside the text editor (inline) for IDEs based on the IntelliJ Platform, inspired by Error Lens and InlineError. + +You can turn this plugin on and off by the keyboard shortcut `alt+u`.

diff --git a/src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java b/src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java index 004cec8..36a3173 100644 --- a/src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java +++ b/src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java @@ -84,24 +84,24 @@ public void scanForProblemsManually() { if (projectManager != null) { List problems = new ArrayList<>(); + if (settingsState.isEnableInlineProblem()) + for (var project : projectManager.getOpenProjects()) { + if (!project.isInitialized() || project.isDisposed()) + continue; - for (var project : projectManager.getOpenProjects()) { - if (!project.isInitialized() || project.isDisposed()) - continue; + FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); + for (var editor : fileEditorManager.getAllEditors()) { - FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); - for (var editor : fileEditorManager.getAllEditors()) { + if (editor.getFile() == null || FileNameUtil.ignoreFile(editor.getFile().getName())) { + continue; + } - if (editor.getFile() == null || FileNameUtil.ignoreFile(editor.getFile().getName())) { - continue; - } - - if (editor instanceof TextEditor) { - var textEditor = (TextEditor) editor; - problems.addAll(getProblemsInEditor(textEditor)); + if (editor instanceof TextEditor) { + var textEditor = (TextEditor) editor; + problems.addAll(getProblemsInEditor(textEditor)); + } } } - } problemManager.updateFromNewActiveProblems(problems); } @@ -119,7 +119,7 @@ public void scanForProblemsManuallyInTextEditor(TextEditor textEditor) { mergingUpdateQueue.queue(new Update("scan") { @Override public void run() { - List problems = getProblemsInEditor(textEditor); + List problems = settingsState.isEnableInlineProblem() ? List.of() : getProblemsInEditor(textEditor); problemManager.updateFromNewActiveProblemsForProjectAndFile( problems, @@ -158,8 +158,7 @@ private List getProblemsInEditor(TextEditor textEditor) { !highlightInfo.getDescription().isEmpty() && problemTextBeginningFilterList.stream() .noneMatch(f -> highlightInfo.getDescription().stripLeading().toLowerCase().startsWith(f.toLowerCase())) && - fileEndOffset >= highlightInfo.getStartOffset() - ; + fileEndOffset >= highlightInfo.getStartOffset(); } return false; diff --git a/src/main/java/org/overengineer/inlineproblems/actions/EnableInlineProblemsAction.java b/src/main/java/org/overengineer/inlineproblems/actions/EnableInlineProblemsAction.java new file mode 100644 index 0000000..895ed82 --- /dev/null +++ b/src/main/java/org/overengineer/inlineproblems/actions/EnableInlineProblemsAction.java @@ -0,0 +1,30 @@ +package org.overengineer.inlineproblems.actions; + +import com.intellij.notification.NotificationType; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.application.ApplicationManager; +import org.jetbrains.annotations.NotNull; +import org.overengineer.inlineproblems.DocumentMarkupModelScanner; +import org.overengineer.inlineproblems.Notifier; +import org.overengineer.inlineproblems.bundles.SettingsBundle; +import org.overengineer.inlineproblems.settings.SettingsState; + +public class EnableInlineProblemsAction extends AnAction { + + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + SettingsState settingsState = SettingsState.getInstance(); + if (settingsState.isEnableInlineProblemsNotifications()) { + Notifier.notify(SettingsBundle.message( + settingsState.isEnableInlineProblem() + ? "settings.enableInlineProblem.disabled" + : "settings.enableInlineProblem.enabled"), + NotificationType.INFORMATION, + anActionEvent.getProject() + ); + } + settingsState.setEnableInlineProblem(!settingsState.isEnableInlineProblem()); + ApplicationManager.getApplication().invokeAndWait(DocumentMarkupModelScanner.getInstance()::scanForProblemsManually); + } +} diff --git a/src/main/java/org/overengineer/inlineproblems/actions/ShowErrorsAction.java b/src/main/java/org/overengineer/inlineproblems/actions/ShowErrorsAction.java new file mode 100644 index 0000000..fa4ecde --- /dev/null +++ b/src/main/java/org/overengineer/inlineproblems/actions/ShowErrorsAction.java @@ -0,0 +1,14 @@ +package org.overengineer.inlineproblems.actions; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import org.jetbrains.annotations.NotNull; +import org.overengineer.inlineproblems.settings.SettingsState; + +public class ShowErrorsAction extends AnAction { + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + SettingsState settingsState = SettingsState.getInstance(); + settingsState.setShowErrors(!settingsState.isShowErrors()); + } +} diff --git a/src/main/java/org/overengineer/inlineproblems/actions/ShowInfosAction.java b/src/main/java/org/overengineer/inlineproblems/actions/ShowInfosAction.java new file mode 100644 index 0000000..b7271cb --- /dev/null +++ b/src/main/java/org/overengineer/inlineproblems/actions/ShowInfosAction.java @@ -0,0 +1,14 @@ +package org.overengineer.inlineproblems.actions; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import org.jetbrains.annotations.NotNull; +import org.overengineer.inlineproblems.settings.SettingsState; + +public class ShowInfosAction extends AnAction { + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + SettingsState settingsState = SettingsState.getInstance(); + settingsState.setShowInfos(!settingsState.isShowInfos()); + } +} diff --git a/src/main/java/org/overengineer/inlineproblems/actions/ShowWarningsAction.java b/src/main/java/org/overengineer/inlineproblems/actions/ShowWarningsAction.java new file mode 100644 index 0000000..41ccf04 --- /dev/null +++ b/src/main/java/org/overengineer/inlineproblems/actions/ShowWarningsAction.java @@ -0,0 +1,14 @@ +package org.overengineer.inlineproblems.actions; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import org.jetbrains.annotations.NotNull; +import org.overengineer.inlineproblems.settings.SettingsState; + +public class ShowWarningsAction extends AnAction { + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + SettingsState settingsState = SettingsState.getInstance(); + settingsState.setShowWarnings(!settingsState.isShowWarnings()); + } +} diff --git a/src/main/java/org/overengineer/inlineproblems/actions/ShowWeakWarningsAction.java b/src/main/java/org/overengineer/inlineproblems/actions/ShowWeakWarningsAction.java new file mode 100644 index 0000000..fa0e0ca --- /dev/null +++ b/src/main/java/org/overengineer/inlineproblems/actions/ShowWeakWarningsAction.java @@ -0,0 +1,14 @@ +package org.overengineer.inlineproblems.actions; + +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import org.jetbrains.annotations.NotNull; +import org.overengineer.inlineproblems.settings.SettingsState; + +public class ShowWeakWarningsAction extends AnAction { + @Override + public void actionPerformed(@NotNull AnActionEvent anActionEvent) { + SettingsState settingsState = SettingsState.getInstance(); + settingsState.setShowWeakWarnings(!settingsState.isShowWeakWarnings()); + } +} diff --git a/src/main/java/org/overengineer/inlineproblems/listeners/MarkupModelProblemListener.java b/src/main/java/org/overengineer/inlineproblems/listeners/MarkupModelProblemListener.java index 66c2776..cb9611b 100644 --- a/src/main/java/org/overengineer/inlineproblems/listeners/MarkupModelProblemListener.java +++ b/src/main/java/org/overengineer/inlineproblems/listeners/MarkupModelProblemListener.java @@ -88,6 +88,8 @@ public static void disposeAll() { } private void handleEvent(EventType type, @NotNull RangeHighlighterEx highlighter) { + if (!settingsState.isEnableInlineProblem()) + return; if (settingsState.getEnabledListener() != Listener.MARKUP_MODEL_LISTENER) return; diff --git a/src/main/java/org/overengineer/inlineproblems/settings/SettingsComponent.java b/src/main/java/org/overengineer/inlineproblems/settings/SettingsComponent.java index 68f59ab..28fc66a 100644 --- a/src/main/java/org/overengineer/inlineproblems/settings/SettingsComponent.java +++ b/src/main/java/org/overengineer/inlineproblems/settings/SettingsComponent.java @@ -55,6 +55,9 @@ public class SettingsComponent { private final ColorPanel infoLabelBackgroundColor = new ColorPanel(); private final ColorPanel infoHighlightColor = new ColorPanel(); + private final JBCheckBox enableInlineProblem = new JBCheckBox(SettingsBundle.message("settings.enableInlineProblem")); + private final JBCheckBox enableInlineProblemsNotifications = new JBCheckBox(SettingsBundle.message("settings.enableInlineProblemsNotifications")); + private final JBCheckBox forceErrorsInSameLine = new JBCheckBox(SettingsBundle.message("settings.forceProblemsInOneLine")); private final JBCheckBox drawBoxesAroundProblemLabels = new JBCheckBox(SettingsBundle.message("settings.drawBoxesAroundProblemLabels")); private final JBCheckBox roundedCornerBoxes = new JBCheckBox(SettingsBundle.message("settings.roundedCornerBoxes")); @@ -115,6 +118,9 @@ public SettingsComponent() { infoLabelBackgroundColor.setSelectedColor(settingsState.getInfoBackgroundColor()); infoHighlightColor.setSelectedColor(settingsState.getInfoHighlightColor()); + enableInlineProblem.setSelected(settingsState.isEnableInlineProblem()); + enableInlineProblemsNotifications.setSelected(settingsState.isEnableInlineProblemsNotifications()); + forceErrorsInSameLine.setSelected(settingsState.isForceProblemsInSameLine()); drawBoxesAroundProblemLabels.setSelected(settingsState.isDrawBoxesAroundErrorLabels()); roundedCornerBoxes.setSelected(settingsState.isRoundedCornerBoxes()); @@ -152,6 +158,8 @@ public SettingsComponent() { settingsPanel = FormBuilder.createFormBuilder() .addComponent(new JBLabel(SettingsBundle.message("settings.submenu.label"))) + .addComponent(enableInlineProblem, 0) + .addComponent(enableInlineProblemsNotifications, 0) .addComponent(drawBoxesAroundProblemLabels, 0) .addComponent(roundedCornerBoxes, 0) .addComponent(fillProblemLabels, 0) @@ -231,6 +239,22 @@ public void setForceErrorsInSameLine(final boolean isSelected) { forceErrorsInSameLine.setSelected(isSelected); } + public boolean isEnableInlineProblem() { + return enableInlineProblem.isSelected(); + } + + public void setEnableInlineProblem(final boolean isSelected) { + enableInlineProblem.setSelected(isSelected); + } + + public boolean isEnableInlineProblemsNotifications() { + return enableInlineProblemsNotifications.isSelected(); + } + + public void setEnableInlineProblemsNotifications(final boolean isSelected) { + enableInlineProblemsNotifications.setSelected(isSelected); + } + public boolean getDrawBoxesAroundProblemLabels() { return drawBoxesAroundProblemLabels.isSelected(); } diff --git a/src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java b/src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java index a3f3299..f26c328 100644 --- a/src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java +++ b/src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java @@ -17,7 +17,8 @@ public class SettingsConfigurable implements Configurable { private final ListenerManager listenerManager = ListenerManager.getInstance(); - SettingsConfigurable() {} + SettingsConfigurable() { + } @Override @NlsContexts.ConfigurableName @@ -42,6 +43,7 @@ public boolean isModified() { SettingsState state = SettingsState.getInstance(); boolean oldStateEqualsNewState = state.isForceProblemsInSameLine() == settingsComponent.isForceErrorsInSameLine() && + state.isEnableInlineProblem() == settingsComponent.isEnableInlineProblem() && state.isDrawBoxesAroundErrorLabels() == settingsComponent.getDrawBoxesAroundProblemLabels() && state.isRoundedCornerBoxes() == settingsComponent.isRoundedCornerBoxes() && state.isUseEditorFont() == settingsComponent.isUseEditorFont() && @@ -133,6 +135,9 @@ public void apply() { state.setInfoBackgroundColor(settingsComponent.getInfoLabelBackgroundColor()); state.setInfoHighlightColor(settingsComponent.getInfoHighlightColor()); + state.setEnableInlineProblem(settingsComponent.isEnableInlineProblem()); + state.setEnableInlineProblemsNotifications(settingsComponent.isEnableInlineProblemsNotifications()); + state.setForceProblemsInSameLine(settingsComponent.isForceErrorsInSameLine()); state.setDrawBoxesAroundErrorLabels(settingsComponent.getDrawBoxesAroundProblemLabels()); state.setRoundedCornerBoxes(settingsComponent.isRoundedCornerBoxes()); @@ -204,6 +209,9 @@ public void reset() { settingsComponent.setInfoLabelBackgroundColor(state.getInfoBackgroundColor()); settingsComponent.setInfoHighlightColor(state.getInfoHighlightColor()); + settingsComponent.setEnableInlineProblem(state.isEnableInlineProblem()); + settingsComponent.setEnableInlineProblemsNotifications(state.isEnableInlineProblemsNotifications()); + settingsComponent.setForceErrorsInSameLine(state.isForceProblemsInSameLine()); settingsComponent.setDrawBoxesAroundProblemLabels(state.isDrawBoxesAroundErrorLabels()); settingsComponent.setRoundedCornerBoxes(state.isRoundedCornerBoxes()); diff --git a/src/main/java/org/overengineer/inlineproblems/settings/SettingsState.java b/src/main/java/org/overengineer/inlineproblems/settings/SettingsState.java index 9e451da..e821f88 100644 --- a/src/main/java/org/overengineer/inlineproblems/settings/SettingsState.java +++ b/src/main/java/org/overengineer/inlineproblems/settings/SettingsState.java @@ -41,6 +41,8 @@ public class SettingsState implements PersistentStateComponent { private boolean highlightInfos = false; private boolean showInfosInGutter = false; private boolean clickableContext = false; + private boolean enableInlineProblem = true; + private boolean enableInlineProblemsNotifications = false; /** * Colors renamed from 'Color' to 'Col' to solve diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index 236a586..74b967b 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -19,23 +19,48 @@ - + key="application.configurable.InlineProblems"/> - + - - + + + + + + + + + + + + - + - - + + \ No newline at end of file diff --git a/src/main/resources/messages/SettingsBundle_en.properties b/src/main/resources/messages/SettingsBundle_en.properties index 844be19..550905a 100644 --- a/src/main/resources/messages/SettingsBundle_en.properties +++ b/src/main/resources/messages/SettingsBundle_en.properties @@ -53,4 +53,20 @@ settings.useEditorFont=Use editor font instead of tooltip font settings.showOnlyHighestPerLine=Show only the problem with the highest severity per line settings.enableHtmlStripping=Enable stripping of HTML in the messages settings.enableXmlUnescaping=Enable unescaping of XML in the messages -settings.enableClickableContext=Enable clickable inline problems for IDE context actions \ No newline at end of file +settings.enableClickableContext=Enable clickable inline problems for IDE context actions +settings.enableInlineProblem=Enable inlineProblems +settings.enableInlineProblemsNotifications=Enable InlineProblems notifications +settings.enableInlineProblem.enabled=Enabling inlineProblems +settings.enableInlineProblem.disabled=Disabling inlineProblems +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.EnableInlineProblemsAction.text=Enable inline Problems +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.ShowErrorsAction.text=Show Errors +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.ShowWarningsAction.text=Show Warnings +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.ShowWeakWarningsAction.text=Show Weak Warnings +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.ShowInfosAction.text=Show Infos +notification.group.InlineProblems=InlineProblems +application.configurable.InlineProblems=InlineProblems diff --git a/src/main/resources/messages/SettingsBundle_zh_CN.properties b/src/main/resources/messages/SettingsBundle_zh_CN.properties index 17e91c6..14c6a8d 100644 --- a/src/main/resources/messages/SettingsBundle_zh_CN.properties +++ b/src/main/resources/messages/SettingsBundle_zh_CN.properties @@ -51,4 +51,19 @@ settings.useEditorFont=\u4F7F\u7528\u7F16\u8F91\u5668\u5B57\u4F53\u800C\u4E0D\u6 settings.showOnlyHighestPerLine=\u4ec5\u663e\u793a\u6bcf\u884c\u4e2d\u6700\u4e25\u91cd\u7684\u95ee\u9898 settings.enableHtmlStripping=Enable stripping of HTML in the messages settings.enableXmlUnescaping=Enable unescaping of XML in the messages -settings.enableClickableContext=Enable clickable inline problems for IDE context actions \ No newline at end of file +settings.enableClickableContext=Enable clickable inline problems for IDE context actions +settings.enableInlineProblem=Enable inlineProblems +settings.enableInlineProblem.enabled=Enabling inlineProblems +settings.enableInlineProblem.disabled=Disabling inlineProblems +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.EnableInlineProblemsAction.text=Enable inline Problems +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.ShowErrorsAction.text=Show Errors +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.ShowWarningsAction.text=Show Warnings +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.ShowWeakWarningsAction.text=Show Weak Warnings +# suppress inspection "UnusedProperty" +action.org.overengineer.inlineproblems.actions.ShowInfosAction.text=Show Infos +notification.group.InlineProblems=InlineProblems +application.configurable.InlineProblems=InlineProblems