Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev -> main for 0.5.3 #55

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,11 +88,13 @@

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));
}
}
Expand All @@ -106,7 +109,7 @@
* 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;
}

Expand Down Expand Up @@ -163,7 +166,7 @@

InlineProblem newProblem = new InlineProblem(
document.getLineNumber(highlightInfo.getStartOffset()),
textEditor.getFile().getPath(),

Check warning on line 169 in src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Nullability and data flow problems

Method invocation `getPath` may produce `NullPointerException`
highlightInfo,
textEditor,
h
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/overengineer/inlineproblems/ListenerManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> enabledListener = new ComboBox<>(availableListeners);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.overengineer.inlineproblems.entities.enums.Listener;

import javax.swing.*;
import java.util.Objects;


public class SettingsConfigurable implements Configurable {
Expand All @@ -19,7 +20,7 @@
SettingsConfigurable() {}

@Override
@NlsContexts.ConfigurableName

Check warning on line 23 in src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.openapi.util.NlsContexts.ConfigurableName' is declared in unstable class 'com.intellij.openapi.util.NlsContexts' marked with @ApiStatus.Experimental

Check warning on line 23 in src/main/java/org/overengineer/inlineproblems/settings/SettingsConfigurable.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Unstable API Usage

'com.intellij.openapi.util.NlsContexts' is marked unstable with @ApiStatus.Experimental
public String getDisplayName() {
return "InlineProblems";
}
Expand Down Expand Up @@ -82,6 +83,7 @@
state.getManualScannerDelay() == settingsComponent.getManualScannerDelay() &&

state.getProblemFilterList().equals(settingsComponent.getProblemFilterList()) &&
state.getFileExtensionBlacklist().equals(settingsComponent.getFileExtensionBlacklist()) &&

state.getAdditionalInfoSeveritiesAsString().equals(settingsComponent.getAdditionalInfoSeverities()) &&
state.getAdditionalWarningSeveritiesAsString().equals(settingsComponent.getAdditionalWarningSeverities()) &&
Expand All @@ -97,6 +99,7 @@
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());
Expand Down Expand Up @@ -140,6 +143,7 @@
state.setEnabledListener(settingsComponent.getEnabledListener());
state.setManualScannerDelay(settingsComponent.getManualScannerDelay());
state.setProblemFilterList(settingsComponent.getProblemFilterList());
state.setFileExtensionBlacklist(settingsComponent.getFileExtensionBlacklist());

state.setAdditionalInfoSeverities(settingsComponent.getAdditionalInfoSeveritiesList());
state.setAdditionalWarningSeverities(settingsComponent.getAdditionalWarningSeveritiesList());
Expand All @@ -152,6 +156,11 @@

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();
}
Expand Down Expand Up @@ -202,6 +211,7 @@
settingsComponent.setEnabledListener(state.getEnabledListener());
settingsComponent.setManualScannerDelay(state.getManualScannerDelay());
settingsComponent.setProblemFilterList(state.getProblemFilterList());
settingsComponent.setFileExtensionBlacklist(state.getFileExtensionBlacklist());

settingsComponent.setAdditionalInfoSeverities(state.getAdditionalInfoSeveritiesAsString());
settingsComponent.setAdditionalWarningSeverities(state.getAdditionalWarningSeveritiesAsString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
private int problemLineLengthOffsetPixels = 50;
private int enabledListener = Listener.MARKUP_MODEL_LISTENER;
private String problemFilterList = "todo;fixme;open in browser";
private String fileExtensionBlacklist = "";

private List<Integer> additionalErrorSeverities = new ArrayList<>();
private List<Integer> additionalWarningSeverities = new ArrayList<>();
Expand Down Expand Up @@ -135,7 +136,7 @@
List<String> newFilterListEntries = List.of("Consider unknown contexts non-blocking");
for (String entry : newFilterListEntries) {
if (!problemFilterList.contains(entry)) {
problemFilterList += ";" + entry;

Check warning on line 139 in src/main/java/org/overengineer/inlineproblems/settings/SettingsState.java

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

String concatenation in loop

String concatenation `+=` in loop
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
2 changes: 2 additions & 0 deletions src/main/resources/messages/SettingsBundle_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading