Skip to content

Commit f2646c4

Browse files
committed
Better EDT error placement.
1 parent adbcf0f commit f2646c4

4 files changed

Lines changed: 52 additions & 19 deletions

File tree

app/src/processing/app/syntax/PdeTextAreaPainter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ protected void paintErrorLine(Graphics gfx, int line, int x) {
151151
int lineOffsetStop = textArea.getLineStopOffset(line);
152152

153153
int wiggleStart = lineOffsetStart + problem.getStartOffset();
154-
int wiggleStop = lineOffsetStart + problem.getStopOffset();
154+
int stopOffset = Editor.getProblemEditorLineStop(problem, lineOffsetStart, lineOffsetStop);
155+
int wiggleStop = lineOffsetStart + stopOffset;
155156

156157
int y = textArea.lineToY(line) + getLineDisplacement();
157158

@@ -330,7 +331,8 @@ public String getToolTipText(MouseEvent event) {
330331
int lineEnd = textArea.getLineStopOffset(line);
331332

332333
int errorStart = lineStart + problem.getStartOffset();
333-
int errorEnd = lineStart + problem.getStopOffset();
334+
int stopOffsetLine = Editor.getProblemEditorLineStop(problem, lineStart, lineEnd);
335+
int errorEnd = lineStart + stopOffsetLine;
334336

335337
int startOffset = Math.max(errorStart, lineStart) - lineStart;
336338
int stopOffset = Math.min(errorEnd, lineEnd) - lineStart;

app/src/processing/app/ui/Editor.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,16 @@ static public void showChanges() {
10281028
}
10291029
}
10301030

1031+
static public int getProblemEditorLineStop(Problem problem, int lineStart, int lineStop) {
1032+
int stopOffset = problem.getStopOffset();
1033+
System.out.println("> " + lineStart + " " + lineStop + " " + stopOffset);
1034+
if (stopOffset == -1) {
1035+
stopOffset = lineStop - lineStart;
1036+
}
1037+
System.out.println("< " + lineStart + " " + lineStop + " " + stopOffset);
1038+
return stopOffset;
1039+
}
1040+
10311041

10321042
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10331043

@@ -2563,8 +2573,11 @@ public void highlight(Problem p) {
25632573
int tabIndex = p.getTabIndex();
25642574
int lineNumber = p.getLineNumber();
25652575
int lineStart = textarea.getLineStartOffset(lineNumber);
2576+
int lineEnd = textarea.getLineStopOffset(lineNumber);
25662577
int tabToStartOffset = lineStart + p.getStartOffset();
2567-
int tabToStopOffset = lineStart + p.getStopOffset();
2578+
2579+
int lineStopOffset = getProblemEditorLineStop(p, lineStart, lineEnd);
2580+
int tabToStopOffset = lineStart + lineStopOffset;
25682581
highlight(tabIndex, tabToStartOffset, tabToStopOffset);
25692582
}
25702583

@@ -2631,7 +2644,8 @@ public List<Problem> findProblems(int line) {
26312644
.filter(p -> {
26322645
int pStartLine = p.getLineNumber();
26332646
int lineOffset = textarea.getLineStartOffset(pStartLine);
2634-
int pEndOffset = lineOffset + p.getStopOffset();
2647+
int stopOffset = p.getStopOffset();
2648+
int pEndOffset = lineOffset + (stopOffset == -1 ? 0 : stopOffset);
26352649
int pEndLine = textarea.getLineOfOffset(pEndOffset);
26362650

26372651
return line >= pStartLine && line <= pEndLine;

java/src/processing/mode/java/ErrorChecker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static private JavaProblem convertIProblem(IProblem iproblem, PreprocSketch ps)
199199
String badCode = ps.getPdeCode(in);
200200
int line = ps.tabOffsetToTabLine(in.tabIndex, in.startTabOffset);
201201
JavaProblem p = JavaProblem.fromIProblem(iproblem, in.tabIndex, line, badCode);
202-
p.setPDEOffsets(0, iproblem.getSourceEnd() - iproblem.getSourceStart());
202+
p.setPDEOffsets(0, -1);
203203
return p;
204204
}
205205
return null;

java/src/processing/mode/java/lsp/PdeAdapter.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ static Offset toLineCol(String s, int offset) {
110110
return new Offset(line, col);
111111
}
112112

113+
static Offset toLineEndCol(String s, int offset) {
114+
Offset before = toLineCol(s, offset);
115+
int remaining = s.substring(offset).indexOf('\n');
116+
return new Offset(before.line, before.col + remaining);
117+
}
118+
113119

114120
/**
115121
* Converts a tabOffset to a position within a tab
@@ -232,21 +238,32 @@ void updateProblems(List<Problem> problems) {
232238
int startOffset = prob.getStartOffset();
233239
int endOffset = prob.getStopOffset();
234240

241+
Position startPosition = new Position(
242+
prob.getLineNumber(),
243+
PdeAdapter
244+
.toLineCol(code.getProgram(), startOffset)
245+
.col - 1
246+
);
247+
248+
Position stopPosition;
249+
if (endOffset == -1) {
250+
stopPosition = new Position(
251+
prob.getLineNumber(),
252+
PdeAdapter
253+
.toLineEndCol(code.getProgram(), startOffset)
254+
.col - 1
255+
);
256+
} else {
257+
stopPosition = new Position(
258+
prob.getLineNumber(),
259+
PdeAdapter
260+
.toLineCol(code.getProgram(), endOffset)
261+
.col - 1
262+
);
263+
}
264+
235265
Diagnostic dia = new Diagnostic(
236-
new Range(
237-
new Position(
238-
prob.getLineNumber(),
239-
PdeAdapter
240-
.toLineCol(code.getProgram(), startOffset)
241-
.col - 1
242-
),
243-
new Position(
244-
prob.getLineNumber(),
245-
PdeAdapter
246-
.toLineCol(code.getProgram(), endOffset)
247-
.col - 1
248-
)
249-
),
266+
new Range(startPosition, stopPosition),
250267
prob.getMessage()
251268
);
252269
dia.setSeverity(

0 commit comments

Comments
 (0)