Skip to content

Commit cf89fec

Browse files
authored
Merge pull request #79 from 0verEngineer/main
0.5.7
2 parents eeea28e + f9edd9b commit cf89fec

20 files changed

+323
-45
lines changed

.idea/misc.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
## [Unreleased]
66

7+
## [0.5.7]
8+
### Changed
9+
- Added feature to enable and disable all problems with a keybind (thanks to khopland)
10+
- Added feature to hover and click in a problem to get the fix context window (thanks to khopland)
11+
712
## [0.5.6]
813
### Changed
914
- Added 2 settings options to disable HTML stripping and XML unescaping

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
<h3 align="center">InlineProblems</h3>
2424

2525
<!-- Plugin description -->
26-
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
26+
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.
27+
28+
You can turn this plugin on and off with the keyboard shortcut `alt+u`, additional shortcuts can be configured in the settings.
2729
<!-- Plugin description end -->
2830

2931
<p align="center">

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pluginGroup = org.OverEngineer
22
pluginName = InlineProblems
33
pluginRepositoryUrl = https://github.com/OverEngineer/InlineProblems
44
# SemVer format -> https://semver.org
5-
pluginVersion = 0.5.6
5+
pluginVersion = 0.5.7
66

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

src/main/java/org/overengineer/inlineproblems/DocumentMarkupModelScanner.java

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,24 @@ public void scanForProblemsManually() {
8484

8585
if (projectManager != null) {
8686
List<InlineProblem> problems = new ArrayList<>();
87+
if (settingsState.isEnableInlineProblem())
88+
for (var project : projectManager.getOpenProjects()) {
89+
if (!project.isInitialized() || project.isDisposed())
90+
continue;
8791

88-
for (var project : projectManager.getOpenProjects()) {
89-
if (!project.isInitialized() || project.isDisposed())
90-
continue;
92+
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
93+
for (var editor : fileEditorManager.getAllEditors()) {
9194

92-
FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
93-
for (var editor : fileEditorManager.getAllEditors()) {
95+
if (editor.getFile() == null || FileNameUtil.ignoreFile(editor.getFile().getName())) {
96+
continue;
97+
}
9498

95-
if (editor.getFile() == null || FileNameUtil.ignoreFile(editor.getFile().getName())) {
96-
continue;
97-
}
98-
99-
if (editor instanceof TextEditor) {
100-
var textEditor = (TextEditor) editor;
101-
problems.addAll(getProblemsInEditor(textEditor));
99+
if (editor instanceof TextEditor) {
100+
var textEditor = (TextEditor) editor;
101+
problems.addAll(getProblemsInEditor(textEditor));
102+
}
102103
}
103104
}
104-
}
105105

106106
problemManager.updateFromNewActiveProblems(problems);
107107
}
@@ -119,7 +119,7 @@ public void scanForProblemsManuallyInTextEditor(TextEditor textEditor) {
119119
mergingUpdateQueue.queue(new Update("scan") {
120120
@Override
121121
public void run() {
122-
List<InlineProblem> problems = getProblemsInEditor(textEditor);
122+
List<InlineProblem> problems = settingsState.isEnableInlineProblem() ? List.of() : getProblemsInEditor(textEditor);
123123

124124
problemManager.updateFromNewActiveProblemsForProjectAndFile(
125125
problems,
@@ -158,8 +158,7 @@ private List<InlineProblem> getProblemsInEditor(TextEditor textEditor) {
158158
!highlightInfo.getDescription().isEmpty() &&
159159
problemTextBeginningFilterList.stream()
160160
.noneMatch(f -> highlightInfo.getDescription().stripLeading().toLowerCase().startsWith(f.toLowerCase())) &&
161-
fileEndOffset >= highlightInfo.getStartOffset()
162-
;
161+
fileEndOffset >= highlightInfo.getStartOffset();
163162
}
164163

165164
return false;

src/main/java/org/overengineer/inlineproblems/InlineDrawer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public void drawProblemLabel(InlineProblem problem) {
3838
problem,
3939
drawDetails.getTextColor(),
4040
drawDetails.getBackgroundColor(),
41+
drawDetails.getTextColor().brighter(),
4142
settings
4243
);
4344

src/main/java/org/overengineer/inlineproblems/InlineProblemLabel.java

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,50 @@
11
package org.overengineer.inlineproblems;
22

3+
import com.intellij.codeInsight.hints.presentation.InputHandler;
4+
import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler;
35
import com.intellij.ide.ui.AntialiasingType;
46
import com.intellij.ide.ui.UISettings;
7+
import com.intellij.openapi.actionSystem.AnAction;
8+
import com.intellij.openapi.actionSystem.IdeActions;
9+
import com.intellij.openapi.actionSystem.ex.ActionUtil;
510
import com.intellij.openapi.editor.Editor;
611
import com.intellij.openapi.editor.EditorCustomElementRenderer;
712
import com.intellij.openapi.editor.Inlay;
13+
import com.intellij.openapi.editor.ScrollType;
814
import com.intellij.openapi.editor.impl.FontInfo;
915
import com.intellij.openapi.editor.markup.GutterIconRenderer;
1016
import com.intellij.openapi.editor.markup.TextAttributes;
17+
import com.intellij.openapi.project.Project;
18+
import com.intellij.psi.PsiFile;
19+
import com.intellij.psi.util.PsiUtilBase;
20+
import com.intellij.ui.paint.EffectPainter;
1121
import lombok.Getter;
1222
import lombok.Setter;
23+
import org.jdesktop.swingx.action.ActionManager;
1324
import org.jetbrains.annotations.NotNull;
1425
import org.jetbrains.annotations.Nullable;
1526
import org.overengineer.inlineproblems.entities.InlineProblem;
1627
import org.overengineer.inlineproblems.settings.SettingsState;
1728
import org.overengineer.inlineproblems.utils.FontUtil;
1829

1930
import java.awt.*;
31+
import java.awt.event.MouseEvent;
2032
import java.awt.font.FontRenderContext;
2133

2234

2335
@Getter
24-
public class InlineProblemLabel implements EditorCustomElementRenderer {
25-
36+
public class InlineProblemLabel implements EditorCustomElementRenderer, InputHandler {
2637
private final String text;
2738
private final Color textColor;
2839
private final Color backgroundColor;
40+
private final Color hoverColor;
2941
private final boolean isDrawBox;
3042
private final boolean isRoundedCorners;
3143
private final boolean isFillBackground;
44+
private boolean hovered;
45+
private final boolean clickableContext;
46+
private Inlay<?> inlay;
47+
private final int actualStartOffset;
3248

3349
@Setter
3450
private boolean isBlockElement;
@@ -47,10 +63,12 @@ public InlineProblemLabel(
4763
final InlineProblem problem,
4864
final Color textColor,
4965
final Color backgroundColor,
66+
final Color hoverColor,
5067
final SettingsState settings
5168
) {
5269
this.textColor = textColor;
5370
this.backgroundColor = backgroundColor;
71+
this.hoverColor = hoverColor;
5472
this.isDrawBox = settings.isDrawBoxesAroundErrorLabels();
5573
this.isRoundedCorners = settings.isRoundedCornerBoxes();
5674
this.text = problem.getText();
@@ -59,6 +77,9 @@ public InlineProblemLabel(
5977

6078
this.isUseEditorFont = settings.isUseEditorFont();
6179
this.inlayFontSizeDelta = settings.getInlayFontSizeDelta();
80+
this.hovered = false;
81+
this.actualStartOffset = problem.getActualStartffset();
82+
this.clickableContext = settings.isClickableContext();
6283
}
6384

6485
@Override
@@ -80,7 +101,7 @@ public int calcWidthInPixels(@NotNull Editor editor) {
80101
@Override
81102
public void paint(@NotNull Inlay inlay, @NotNull Graphics graphics, @NotNull Rectangle targetRegion, @NotNull TextAttributes textAttributes) {
82103
Editor editor = inlay.getEditor();
83-
104+
this.inlay = inlay;
84105
// These offsets are applied here and not in the calc functions itself because we use it to shrink the drawn stuff a little bit
85106
int width = calcWidthInPixels(inlay) + DRAW_BOX_WIDTH_OFFSET;
86107
int height = calcHeightInPixels(inlay) + DRAW_BOX_HEIGHT_OFFSET;
@@ -92,7 +113,7 @@ public void paint(@NotNull Inlay inlay, @NotNull Graphics graphics, @NotNull Rec
92113
// Apply delta on the boxes
93114
if (inlayFontSizeDelta != 0 && editorFontSize > inlayFontSizeDelta) {
94115
height -= inlayFontSizeDelta;
95-
targetRegionY += (int)(inlayFontSizeDelta / 1.5);
116+
targetRegionY += (int) (inlayFontSizeDelta / 1.5);
96117
}
97118

98119
if (isDrawBox) {
@@ -118,14 +139,13 @@ public void paint(@NotNull Inlay inlay, @NotNull Graphics graphics, @NotNull Rec
118139
5
119140
);
120141
}
121-
}
122-
else {
123-
graphics.drawRect(
124-
targetRegion.x,
125-
targetRegionY,
126-
width,
127-
height
128-
);
142+
} else {
143+
graphics.drawRect(
144+
targetRegion.x,
145+
targetRegionY,
146+
width,
147+
height
148+
);
129149

130150
if (isFillBackground) {
131151
graphics.fillRect(
@@ -138,7 +158,7 @@ public void paint(@NotNull Inlay inlay, @NotNull Graphics graphics, @NotNull Rec
138158
}
139159
}
140160

141-
graphics.setColor(textColor);
161+
graphics.setColor(hovered ? hoverColor : textColor);
142162

143163
graphics.setFont(FontUtil.getActiveFont(editor));
144164

@@ -147,10 +167,63 @@ public void paint(@NotNull Inlay inlay, @NotNull Graphics graphics, @NotNull Rec
147167
targetRegion.x + DRAW_STRING_LINE_PLACEMENT_OFFSET_X,
148168
targetRegion.y + DRAW_STRING_LINE_PLACEMENT_OFFSET_Y + editor.getAscent()
149169
);
170+
if (hovered)
171+
EffectPainter.LINE_UNDERSCORE.paint(
172+
(Graphics2D) graphics,
173+
targetRegion.x - DRAW_BOX_WIDTH_OFFSET,
174+
targetRegion.y + editor.getAscent() ,
175+
width + (DRAW_BOX_WIDTH_OFFSET * 2),
176+
editor.getAscent(),
177+
FontUtil.getActiveFont(editor));
178+
}
179+
180+
private void setHovered(boolean hovered) {
181+
if (!this.clickableContext || this.hovered == hovered) {
182+
return;
183+
}
184+
this.hovered = hovered;
185+
if (inlay != null)
186+
inlay.repaint();
150187
}
151188

152189
@Override
153190
public @Nullable GutterIconRenderer calcGutterIconRenderer(@NotNull Inlay inlay) {
154191
return EditorCustomElementRenderer.super.calcGutterIconRenderer(inlay);
155192
}
193+
194+
@Override
195+
public void mouseClicked(@NotNull MouseEvent mouseEvent, @NotNull Point point) {
196+
if (!clickableContext) {
197+
return;
198+
}
199+
if (mouseEvent.getButton() == MouseEvent.BUTTON1) {
200+
mouseEvent.consume();
201+
202+
var editor = inlay.getEditor();
203+
editor.getCaretModel().moveToOffset(actualStartOffset);
204+
editor.getScrollingModel().scrollToCaret(ScrollType.CENTER);
205+
206+
var action = ActionManager.getInstance().getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS);
207+
if (action == null) {
208+
Project project = editor.getProject();
209+
if (project == null) return;
210+
PsiFile psiFileInEditor = PsiUtilBase.getPsiFileInEditor(editor, project);
211+
if (psiFileInEditor == null) return;
212+
new ShowIntentionActionsHandler().invoke(project, editor, psiFileInEditor, false);
213+
} else {
214+
ActionUtil.invokeAction((AnAction) action, editor.getComponent(), "EditorInlay", null, null);
215+
}
216+
}
217+
}
218+
219+
@Override
220+
public void mouseMoved(@NotNull MouseEvent mouseEvent, @NotNull Point point) {
221+
setHovered(true);
222+
}
223+
224+
@Override
225+
public void mouseExited() {
226+
setHovered(false);
227+
}
228+
156229
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.overengineer.inlineproblems.actions;
2+
3+
import com.intellij.notification.NotificationType;
4+
import com.intellij.openapi.actionSystem.AnAction;
5+
import com.intellij.openapi.actionSystem.AnActionEvent;
6+
import com.intellij.openapi.application.ApplicationManager;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.overengineer.inlineproblems.DocumentMarkupModelScanner;
9+
import org.overengineer.inlineproblems.Notifier;
10+
import org.overengineer.inlineproblems.bundles.SettingsBundle;
11+
import org.overengineer.inlineproblems.settings.SettingsState;
12+
13+
public class EnableInlineProblemsAction extends AnAction {
14+
15+
@Override
16+
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
17+
SettingsState settingsState = SettingsState.getInstance();
18+
if (settingsState.isEnableInlineProblemsNotifications()) {
19+
Notifier.notify(SettingsBundle.message(
20+
settingsState.isEnableInlineProblem()
21+
? "settings.enableInlineProblem.disabled"
22+
: "settings.enableInlineProblem.enabled"),
23+
NotificationType.INFORMATION,
24+
anActionEvent.getProject()
25+
);
26+
}
27+
settingsState.setEnableInlineProblem(!settingsState.isEnableInlineProblem());
28+
ApplicationManager.getApplication().invokeAndWait(DocumentMarkupModelScanner.getInstance()::scanForProblemsManually);
29+
}
30+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.overengineer.inlineproblems.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.overengineer.inlineproblems.settings.SettingsState;
7+
8+
public class ShowErrorsAction extends AnAction {
9+
@Override
10+
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
11+
SettingsState settingsState = SettingsState.getInstance();
12+
settingsState.setShowErrors(!settingsState.isShowErrors());
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.overengineer.inlineproblems.actions;
2+
3+
import com.intellij.openapi.actionSystem.AnAction;
4+
import com.intellij.openapi.actionSystem.AnActionEvent;
5+
import org.jetbrains.annotations.NotNull;
6+
import org.overengineer.inlineproblems.settings.SettingsState;
7+
8+
public class ShowInfosAction extends AnAction {
9+
@Override
10+
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
11+
SettingsState settingsState = SettingsState.getInstance();
12+
settingsState.setShowInfos(!settingsState.isShowInfos());
13+
}
14+
}

0 commit comments

Comments
 (0)