diff --git a/CHANGELOG.md b/CHANGELOG.md index dabc8d3..fb53fc8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ ## [Unreleased] +## [0.5.3] +### Added +- Ability to blacklist file extensions so that the plugin will not show anything on blacklisted files + ## [0.5.2] ### Added - Compability with 2024.1 diff --git a/gradle.properties b/gradle.properties index a69b43f..9684891 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ pluginGroup = org.OverEngineer pluginName = InlineProblems pluginRepositoryUrl = https://github.com/OverEngineer/InlineProblems # SemVer format -> https://semver.org -pluginVersion = 0.5.2 +pluginVersion = 0.5.3 # Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html pluginSinceBuild = 212.5 diff --git a/src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java b/src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java index e100492..0f80415 100644 --- a/src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java +++ b/src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java @@ -19,6 +19,7 @@ import org.overengineer.inlineproblems.entities.enums.Listener; import org.overengineer.inlineproblems.listeners.HighlightProblemListener; import org.overengineer.inlineproblems.settings.SettingsState; +import org.overengineer.inlineproblems.utils.FileNameUtil; import java.util.ArrayList; import java.util.Arrays; @@ -87,11 +88,13 @@ public void scanForProblemsManually() { FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); for (var editor : fileEditorManager.getAllEditors()) { + + if (editor.getFile() == null || FileNameUtil.ignoreFile(editor.getFile().getName())) { + continue; + } + if (editor instanceof TextEditor) { var textEditor = (TextEditor) editor; - if (textEditor.getFile() == null) { - continue; - } problems.addAll(getProblemsInEditor(textEditor)); } } @@ -106,7 +109,7 @@ public void scanForProblemsManually() { * millisecond if the HighlightProblemListener is used. */ public void scanForProblemsManuallyInTextEditor(TextEditor textEditor) { - if (textEditor.getFile() == null) { + if (textEditor.getFile() == null || FileNameUtil.ignoreFile(textEditor.getFile().getName())) { return; } diff --git a/src/main/java/org/overengineer/inlineproblems/ListenerManager.java b/src/main/java/org/overengineer/inlineproblems/ListenerManager.java index a00f2b1..30b799d 100644 --- a/src/main/java/org/overengineer/inlineproblems/ListenerManager.java +++ b/src/main/java/org/overengineer/inlineproblems/ListenerManager.java @@ -9,6 +9,7 @@ import org.overengineer.inlineproblems.listeners.HighlightProblemListener; import org.overengineer.inlineproblems.listeners.MarkupModelProblemListener; import org.overengineer.inlineproblems.settings.SettingsState; +import org.overengineer.inlineproblems.utils.FileNameUtil; public class ListenerManager { @@ -39,6 +40,11 @@ public void installMarkupModelListenerOnAllProjects() { for (var project : manager.getOpenProjects()) { FileEditorManager fileEditorManager = FileEditorManager.getInstance(project); for (var editor : fileEditorManager.getAllEditors()) { + + if (editor.getFile() == null || FileNameUtil.ignoreFile(editor.getFile().getName())) { + continue; + } + if (editor instanceof TextEditor) { MarkupModelProblemListener.setup((TextEditor) editor); logger.debug("Installing MarkupModelListener"); @@ -53,6 +59,11 @@ public void resetAndRescan() { documentMarkupModelScanner.scanForProblemsManually(); } + public void resetMarkupModelProblemListeners() { + MarkupModelProblemListener.disposeAll(); + installMarkupModelListenerOnAllProjects(); + } + public void changeListener() { if (settings.getEnabledListener() != Listener.MARKUP_MODEL_LISTENER) { MarkupModelProblemListener.disposeAll(); diff --git a/src/main/java/org/overengineer/inlineproblems/listeners/FileEditorListener.java b/src/main/java/org/overengineer/inlineproblems/listeners/FileEditorListener.java index 0ae6589..aab7a87 100644 --- a/src/main/java/org/overengineer/inlineproblems/listeners/FileEditorListener.java +++ b/src/main/java/org/overengineer/inlineproblems/listeners/FileEditorListener.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import org.overengineer.inlineproblems.entities.enums.Listener; import org.overengineer.inlineproblems.settings.SettingsState; +import org.overengineer.inlineproblems.utils.FileNameUtil; import java.util.Arrays; @@ -23,6 +24,10 @@ public void fileOpenedSync( if (settingsState.getEnabledListener() != Listener.MARKUP_MODEL_LISTENER) return; + if (FileNameUtil.ignoreFile(file.getName())) { + return; + } + Arrays.stream(editors.first) .filter(e -> e instanceof TextEditor) .map(e -> (TextEditor)e) diff --git a/src/main/java/org/overengineer/inlineproblems/listeners/HighlightProblemListener.java b/src/main/java/org/overengineer/inlineproblems/listeners/HighlightProblemListener.java index 9ff1e32..4939646 100644 --- a/src/main/java/org/overengineer/inlineproblems/listeners/HighlightProblemListener.java +++ b/src/main/java/org/overengineer/inlineproblems/listeners/HighlightProblemListener.java @@ -12,6 +12,7 @@ import org.overengineer.inlineproblems.DocumentMarkupModelScanner; import org.overengineer.inlineproblems.entities.enums.Listener; import org.overengineer.inlineproblems.settings.SettingsState; +import org.overengineer.inlineproblems.utils.FileNameUtil; public class HighlightProblemListener implements HighlightInfoFilter { @@ -28,6 +29,10 @@ public boolean accept(@NotNull HighlightInfo highlightInfo, @Nullable PsiFile fi if (file == null || !file.isValid()) return true; + if (FileNameUtil.ignoreFile(file.getName())) { + return true; + } + if (!file.getProject().isDisposed()) { ApplicationManager.getApplication().invokeLater(() -> handleAccept(file)); } diff --git a/src/main/java/org/overengineer/inlineproblems/settings/SettingsComponent.java b/src/main/java/org/overengineer/inlineproblems/settings/SettingsComponent.java index 3cfd00d..ff747b7 100644 --- a/src/main/java/org/overengineer/inlineproblems/settings/SettingsComponent.java +++ b/src/main/java/org/overengineer/inlineproblems/settings/SettingsComponent.java @@ -67,6 +67,7 @@ public class SettingsComponent { private final JBCheckBox boldProblemLabels = new JBCheckBox(SettingsBundle.message("settings.boldProblemLabels")); private final JBCheckBox italicProblemLabels = new JBCheckBox(SettingsBundle.message("settings.italicProblemLabels")); private final JBTextField problemFilterList = new JBTextField(); + private final JBTextField fileExtensionBlacklist = new JBTextField(); private final String[] availableListeners = {HighlightProblemListener.NAME, MarkupModelProblemListener.NAME, DocumentMarkupModelScanner.NAME}; private final JComboBox enabledListener = new ComboBox<>(availableListeners); @@ -137,6 +138,7 @@ public SettingsComponent() { additionalErrorSeverities.setText(settingsState.getAdditionalErrorSeveritiesAsString()); problemFilterList.setText(settingsState.getProblemFilterList()); + fileExtensionBlacklist.setText(settingsState.getFileExtensionBlacklist()); enabledListener.setSelectedItem(Optional.of(settingsState.getEnabledListener())); Dimension enabledListenerDimension = enabledListener.getPreferredSize(); @@ -166,6 +168,8 @@ public SettingsComponent() { .addTooltip(SettingsBundle.message("settings.inlaySizeDeltaTooltip")) .addLabeledComponent(new JLabel(SettingsBundle.message("settings.problemFilterListLabel")), problemFilterList) .addTooltip(SettingsBundle.message("settings.problemFilterListTooltip")) + .addLabeledComponent(new JLabel(SettingsBundle.message("settings.fileExtensionBlacklistLabel")), fileExtensionBlacklist) + .addTooltip(SettingsBundle.message("settings.fileExtensionBlaclistTooltip")) .addSeparator() .addComponent(new JBLabel(SettingsBundle.message("settings.submenu.colors"))) .addComponent(showErrors) @@ -493,6 +497,14 @@ public void setProblemFilterList(final String newText) { problemFilterList.setText(newText); } + public String getFileExtensionBlacklist() { + return fileExtensionBlacklist.getText(); + } + + public void setFileExtensionBlacklist(final String newText) { + fileExtensionBlacklist.setText(newText); + } + public String getAdditionalInfoSeverities() { return additionalInfoSeverities.getText(); } diff --git a/src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java b/src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java index 14d5b1a..af60cad 100644 --- a/src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java +++ b/src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java @@ -8,6 +8,7 @@ import org.overengineer.inlineproblems.entities.enums.Listener; import javax.swing.*; +import java.util.Objects; public class SettingsConfigurable implements Configurable { @@ -82,6 +83,7 @@ public boolean isModified() { state.getManualScannerDelay() == settingsComponent.getManualScannerDelay() && state.getProblemFilterList().equals(settingsComponent.getProblemFilterList()) && + state.getFileExtensionBlacklist().equals(settingsComponent.getFileExtensionBlacklist()) && state.getAdditionalInfoSeveritiesAsString().equals(settingsComponent.getAdditionalInfoSeverities()) && state.getAdditionalWarningSeveritiesAsString().equals(settingsComponent.getAdditionalWarningSeverities()) && @@ -97,6 +99,7 @@ public void apply() { SettingsState state = SettingsState.getInstance(); boolean listenerChanged = state.getEnabledListener() != settingsComponent.getEnabledListener(); + boolean fileExtensionBlacklistChanged = !Objects.equals(state.getFileExtensionBlacklist(), settingsComponent.getFileExtensionBlacklist()); boolean manualScannerDelayChanged = state.getManualScannerDelay() != settingsComponent.getManualScannerDelay(); state.setShowErrors(settingsComponent.isShowErrors()); @@ -140,6 +143,7 @@ public void apply() { state.setEnabledListener(settingsComponent.getEnabledListener()); state.setManualScannerDelay(settingsComponent.getManualScannerDelay()); state.setProblemFilterList(settingsComponent.getProblemFilterList()); + state.setFileExtensionBlacklist(settingsComponent.getFileExtensionBlacklist()); state.setAdditionalInfoSeverities(settingsComponent.getAdditionalInfoSeveritiesList()); state.setAdditionalWarningSeverities(settingsComponent.getAdditionalWarningSeveritiesList()); @@ -152,6 +156,11 @@ public void apply() { listenerManager.resetAndRescan(); + // When the blacklist changes we need to re-apply all MarkupModelProblemListeners + if (fileExtensionBlacklistChanged && state.getEnabledListener() == Listener.MARKUP_MODEL_LISTENER) { + listenerManager.resetMarkupModelProblemListeners(); + } + if (listenerChanged) { listenerManager.changeListener(); } @@ -202,6 +211,7 @@ public void reset() { settingsComponent.setEnabledListener(state.getEnabledListener()); settingsComponent.setManualScannerDelay(state.getManualScannerDelay()); settingsComponent.setProblemFilterList(state.getProblemFilterList()); + settingsComponent.setFileExtensionBlacklist(state.getFileExtensionBlacklist()); settingsComponent.setAdditionalInfoSeverities(state.getAdditionalInfoSeveritiesAsString()); settingsComponent.setAdditionalWarningSeverities(state.getAdditionalWarningSeveritiesAsString()); diff --git a/src/main/java/org/overengineer/inlineproblems/settings/SettingsState.java b/src/main/java/org/overengineer/inlineproblems/settings/SettingsState.java index 5bf9a2b..57923ed 100644 --- a/src/main/java/org/overengineer/inlineproblems/settings/SettingsState.java +++ b/src/main/java/org/overengineer/inlineproblems/settings/SettingsState.java @@ -96,6 +96,7 @@ public class SettingsState implements PersistentStateComponent { private int problemLineLengthOffsetPixels = 50; private int enabledListener = Listener.MARKUP_MODEL_LISTENER; private String problemFilterList = "todo;fixme;open in browser"; + private String fileExtensionBlacklist = ""; private List additionalErrorSeverities = new ArrayList<>(); private List additionalWarningSeverities = new ArrayList<>(); diff --git a/src/main/java/org/overengineer/inlineproblems/utils/FileNameUtil.java b/src/main/java/org/overengineer/inlineproblems/utils/FileNameUtil.java new file mode 100644 index 0000000..94bd09e --- /dev/null +++ b/src/main/java/org/overengineer/inlineproblems/utils/FileNameUtil.java @@ -0,0 +1,19 @@ +package org.overengineer.inlineproblems.utils; + +import org.overengineer.inlineproblems.settings.SettingsState; + +public class FileNameUtil { + public static boolean ignoreFile(String fileName) { + boolean ignore = false; + + for (var e : SettingsState.getInstance().getFileExtensionBlacklist().split(";")) { + if (e.isBlank() || e.isEmpty() || e.equals(";")) continue; + if (fileName.endsWith(e)) { + ignore = true; + break; + } + } + + return ignore; + } +} diff --git a/src/main/resources/messages/SettingsBundle_en.properties b/src/main/resources/messages/SettingsBundle_en.properties index 1ef7387..90809ee 100644 --- a/src/main/resources/messages/SettingsBundle_en.properties +++ b/src/main/resources/messages/SettingsBundle_en.properties @@ -28,6 +28,8 @@ settings.inlaySizeDelta=Inlay size delta settings.inlaySizeDeltaTooltip=Used to have smaller font size for the inlays, should be smaller than editor font size settings.problemFilterListLabel=Problem filter list settings.problemFilterListTooltip=Semicolon separated list of problem text beginnings that will not be handled +settings.fileExtensionBlacklistLabel=File extension blacklist +settings.fileExtensionBlaclistTooltip=Semicolon separated list of file extensions to ignore (like ".java;.md") settings.submenu.colors=Colors settings.errorTextColor=Error text color: settings.errorLabelBorderColor=Error label border color: