Skip to content

Commit

Permalink
Merge pull request #35 from 0verEngineer/main
Browse files Browse the repository at this point in the history
Release 0.4.3
  • Loading branch information
0verEngineer authored Jun 8, 2023
2 parents 9b34723 + ce8442a commit 185634f
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 144 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,23 @@

## [Unreleased]

## [0.4.3]

### Added
- Some performance improvements
- Description for the listeners in the settings
- Configurable delay for the manual scan listener
- Support for new EAP versions

### Changed
- MarkupModelListener is now the default listener

### Fixed
- Some possible null pointer exceptions
- invokeLater queuing issue of MarkupModelListener if used with the only one problem per line feature
- Cache of activeProblems is now thread safe
- CustomSeverity bugs that leads to useless problem updates

## [0.4.2]

### Added
Expand Down Expand Up @@ -95,6 +112,8 @@
- Initial release with basic functionality

[Unreleased]: https://github.com/OverEngineer/InlineProblems/compare/v0.4.0...HEAD
[0.4.3]: https://github.com/0verEngineer/InlineProblems/compare/v0.4.2...v0.4.3
[0.4.2]: https://github.com/0verEngineer/InlineProblems/compare/v0.4.0...v0.4.2
[0.4.0]: https://github.com/0verEngineer/InlineProblems/compare/v0.3.3...v0.4.0
[0.3.3]: https://github.com/0verEngineer/InlineProblems/compare/0.3.2...v0.3.3
[0.3.2]: https://github.com/0verEngineer/InlineProblems/compare/0.3.1...0.3.2
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ pluginGroup = org.OverEngineer
pluginName = InlineProblems
pluginRepositoryUrl = https://github.com/OverEngineer/InlineProblems
# SemVer format -> https://semver.org
pluginVersion = 0.4.2
pluginVersion = 0.4.3

# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
pluginSinceBuild = 212.5
pluginUntilBuild = 231.*
pluginUntilBuild = 233.*

# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType = IC
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package org.overengineer.inlineproblems;

import com.intellij.codeInsight.daemon.impl.HighlightInfo;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.editor.impl.DocumentMarkupModel;
import com.intellij.openapi.editor.markup.RangeHighlighter;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.util.Disposer;
import com.intellij.util.concurrency.AppExecutorUtil;
import com.intellij.util.ui.update.MergingUpdateQueue;
import com.intellij.util.ui.update.Update;
import org.overengineer.inlineproblems.entities.InlineProblem;
import org.overengineer.inlineproblems.entities.enums.Listener;
import org.overengineer.inlineproblems.listeners.HighlightProblemListener;
Expand All @@ -24,25 +27,41 @@
import java.util.concurrent.TimeUnit;


public class DocumentMarkupModelScanner {
public class DocumentMarkupModelScanner implements Disposable {
private final ProblemManager problemManager = ApplicationManager.getApplication().getService(ProblemManager.class);

private final SettingsState settingsState = SettingsState.getInstance();

private final Logger logger = Logger.getInstance(DocumentMarkupModelScanner.class);

private int delayMilliseconds = HighlightProblemListener.ADDITIONAL_MANUAL_SCAN_DELAY_MILLIS;

// Used to bypass the listener setting
private boolean isManualScanEnabled = true;

private static DocumentMarkupModelScanner instance;

private final MergingUpdateQueue mergingUpdateQueue;

private ScheduledFuture<?> scheduledFuture;

public static final String NAME = "ManualScanner";

public static final int MANUAL_SCAN_DELAY_MILLIS = 250;
private DocumentMarkupModelScanner() {
Disposer.register(problemManager, this);

mergingUpdateQueue = new MergingUpdateQueue(
"DocumentMarkupModelScannerQueue",
10,
true,
null,
this,
null,
true
);

SettingsState settingsState = SettingsState.getInstance();
if (settingsState.getEnabledListener() == Listener.MANUAL_SCANNING) {
delayMilliseconds = settingsState.getManualScannerDelay();
}

createAndStartScheduledFuture();
}

public static DocumentMarkupModelScanner getInstance() {
if (instance == null)
Expand All @@ -51,12 +70,9 @@ public static DocumentMarkupModelScanner getInstance() {
return instance;
}

private DocumentMarkupModelScanner() {
if (settingsState.getEnabledListener() == Listener.MANUAL_SCANNING) {
delayMilliseconds = MANUAL_SCAN_DELAY_MILLIS;
}

createAndStartScheduledFuture();
@Override
public void dispose() {
mergingUpdateQueue.cancelAllUpdates();
}

public void scanForProblemsManually() {
Expand All @@ -66,10 +82,17 @@ public void scanForProblemsManually() {
List<InlineProblem> problems = new ArrayList<>();

for (var project : projectManager.getOpenProjects()) {
if (!project.isInitialized() || project.isDisposed())
continue;

FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
for (var editor : fileEditorManager.getAllEditors()) {
if (editor instanceof TextEditor) {
problems.addAll(getProblemsInEditor((TextEditor) editor));
var textEditor = (TextEditor) editor;
if (textEditor.getFile() == null) {
continue;
}
problems.addAll(getProblemsInEditor(textEditor));
}
}
}
Expand All @@ -78,13 +101,27 @@ public void scanForProblemsManually() {
}
}

/**
* This function is queued in the mergingUpdateQueue because it is called frequently, this can be multiple times per
* millisecond if the HighlightProblemListener is used.
*/
public void scanForProblemsManuallyInTextEditor(TextEditor textEditor) {
List<InlineProblem> problems = getProblemsInEditor(textEditor);
problemManager.updateFromNewActiveProblemsForProjectAndFile(
problems,
textEditor.getEditor().getProject(),
textEditor.getFile().getPath()
);
if (textEditor.getFile() == null) {
return;
}

mergingUpdateQueue.queue(new Update("scan") {
@Override
public void run() {
List<InlineProblem> problems = getProblemsInEditor(textEditor);

problemManager.updateFromNewActiveProblemsForProjectAndFile(
problems,
textEditor.getEditor().getProject(),
textEditor.getFile().getPath()
);
}
});
}

private List<InlineProblem> getProblemsInEditor(TextEditor textEditor) {
Expand All @@ -108,52 +145,49 @@ private List<InlineProblem> getProblemsInEditor(TextEditor textEditor) {
);

Arrays.stream(highlighters)
.filter(RangeMarker::isValid)
.filter(h -> {
if (h.getErrorStripeTooltip() instanceof HighlightInfo) {
if (h.isValid() && h.getErrorStripeTooltip() instanceof HighlightInfo) {
HighlightInfo highlightInfo = (HighlightInfo) h.getErrorStripeTooltip();
return highlightInfo.getDescription() != null &&
!highlightInfo.getDescription().isEmpty() &&
problemTextBeginningFilterList.stream()
.noneMatch(f -> highlightInfo.getDescription().stripLeading().toLowerCase().startsWith(f.toLowerCase()));
.noneMatch(f -> highlightInfo.getDescription().stripLeading().toLowerCase().startsWith(f.toLowerCase())) &&
fileEndOffset >= highlightInfo.getStartOffset()
;
}

return false;
})
.forEach(h -> {
HighlightInfo highlightInfo = (HighlightInfo) h.getErrorStripeTooltip();
if (fileEndOffset >= highlightInfo.getStartOffset()) {
int line = document.getLineNumber(highlightInfo.getStartOffset());

InlineProblem newProblem = new InlineProblem(
line,
highlightInfo,
textEditor,
h
);

problems.add(newProblem);
InlineProblem newProblem = new InlineProblem(
document.getLineNumber(highlightInfo.getStartOffset()),
textEditor.getFile().getPath(),
highlightInfo,
textEditor,
h
);

problemManager.applyCustomSeverity(newProblem);
if (problemManager.shouldProblemBeIgnored(newProblem.getSeverity())) {
return;
}

problems.add(newProblem);
});

return problems;
}

public void setIsManualScanEnabled(boolean isEnabled) {
isManualScanEnabled = isEnabled;

if (isEnabled && scheduledFuture.isCancelled()) {
createAndStartScheduledFuture();
}
else if (!isEnabled && !scheduledFuture.isCancelled()) {
cancelScheduledFuture();
}
public void restartManualScan() {
cancelScheduledFuture();
createAndStartScheduledFuture();
}

public void setDelayMilliseconds(int newDelayMilliseconds) {
delayMilliseconds = newDelayMilliseconds;
cancelScheduledFuture();
createAndStartScheduledFuture();
restartManualScan();
}

private void cancelScheduledFuture() {
Expand All @@ -166,8 +200,8 @@ private void cancelScheduledFuture() {

private void createAndStartScheduledFuture() {
scheduledFuture = AppExecutorUtil.getAppScheduledExecutorService().scheduleWithFixedDelay(
() -> ApplicationManager.getApplication().invokeLater(this::scanForProblemsManually),
0,
() -> ApplicationManager.getApplication().invokeAndWait(this::scanForProblemsManually),
2000,
delayMilliseconds,
TimeUnit.MILLISECONDS
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public class InlineProblemLabel implements EditorCustomElementRenderer {
@Setter
private boolean isBlockElement;

private int inlayFontSizeDelta;
private boolean isUseEditorFont = false;
private final int inlayFontSizeDelta;
private final boolean isUseEditorFont;

private static final int WIDTH_OFFSET = 7;
private static final int DRAW_BOX_HEIGHT_OFFSET = -2; // Makes the box lines visible even if line below / above is highlighted
Expand Down Expand Up @@ -77,11 +77,6 @@ public int calcWidthInPixels(@NotNull Editor editor) {
return fontMetrics.stringWidth(text) + WIDTH_OFFSET;
}

@Override
public int calcHeightInPixels(@NotNull Inlay inlay) {
return inlay.getEditor().getLineHeight();
}

@Override
public void paint(@NotNull Inlay inlay, @NotNull Graphics graphics, @NotNull Rectangle targetRegion, @NotNull TextAttributes textAttributes) {
Editor editor = inlay.getEditor();
Expand All @@ -96,7 +91,7 @@ public void paint(@NotNull Inlay inlay, @NotNull Graphics graphics, @NotNull Rec

// Apply delta on the boxes
if (inlayFontSizeDelta != 0 && editorFontSize > inlayFontSizeDelta) {
height = height - inlayFontSizeDelta;
height -= inlayFontSizeDelta;
targetRegionY += (int)(inlayFontSizeDelta / 1.5);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ public void changeListener() {
}

if (settings.getEnabledListener() == Listener.MARKUP_MODEL_LISTENER) {
documentMarkupModelScanner.setIsManualScanEnabled(false);
documentMarkupModelScanner.setDelayMilliseconds(HighlightProblemListener.ADDITIONAL_MANUAL_SCAN_DELAY_MILLIS);
installMarkupModelListenerOnAllProjects();
}
else if (settings.getEnabledListener() == Listener.HIGHLIGHT_PROBLEMS_LISTENER) {
documentMarkupModelScanner.setIsManualScanEnabled(true);
documentMarkupModelScanner.setDelayMilliseconds(HighlightProblemListener.ADDITIONAL_MANUAL_SCAN_DELAY_MILLIS);
}
else if (settings.getEnabledListener() == Listener.MANUAL_SCANNING) {
documentMarkupModelScanner.setIsManualScanEnabled(true);
documentMarkupModelScanner.setDelayMilliseconds(DocumentMarkupModelScanner.MANUAL_SCAN_DELAY_MILLIS);
documentMarkupModelScanner.setDelayMilliseconds(settings.getManualScannerDelay());
}

documentMarkupModelScanner.restartManualScan();
}
}
Loading

0 comments on commit 185634f

Please sign in to comment.