Skip to content

Commit f1da373

Browse files
authored
Merge pull request #772 from processing/full-line-edt
Full line edt
2 parents adbcf0f + 8db755f commit f1da373

File tree

5 files changed

+50
-20
lines changed

5 files changed

+50
-20
lines changed

app/src/processing/app/Problem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public interface Problem {
7878
* Get the exact character on which this problem ends in code line relative.
7979
*
8080
* @return Number of characters past the start of the line if known where the
81-
* code associated with the Problem ends.
81+
* code associated with the Problem ends. If -1, should use the whole line.
8282
*/
8383
public int getStopOffset();
8484

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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,6 +1028,14 @@ static public void showChanges() {
10281028
}
10291029
}
10301030

1031+
static public int getProblemEditorLineStop(Problem problem, int lineStart, int lineStop) {
1032+
int stopOffset = problem.getStopOffset();
1033+
if (stopOffset == -1) {
1034+
stopOffset = lineStop - lineStart;
1035+
}
1036+
return stopOffset;
1037+
}
1038+
10311039

10321040
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10331041

@@ -2563,8 +2571,11 @@ public void highlight(Problem p) {
25632571
int tabIndex = p.getTabIndex();
25642572
int lineNumber = p.getLineNumber();
25652573
int lineStart = textarea.getLineStartOffset(lineNumber);
2574+
int lineEnd = textarea.getLineStopOffset(lineNumber);
25662575
int tabToStartOffset = lineStart + p.getStartOffset();
2567-
int tabToStopOffset = lineStart + p.getStopOffset();
2576+
2577+
int lineStopOffset = getProblemEditorLineStop(p, lineStart, lineEnd);
2578+
int tabToStopOffset = lineStart + lineStopOffset;
25682579
highlight(tabIndex, tabToStartOffset, tabToStopOffset);
25692580
}
25702581

@@ -2631,7 +2642,8 @@ public List<Problem> findProblems(int line) {
26312642
.filter(p -> {
26322643
int pStartLine = p.getLineNumber();
26332644
int lineOffset = textarea.getLineStartOffset(pStartLine);
2634-
int pEndOffset = lineOffset + p.getStopOffset();
2645+
int stopOffset = p.getStopOffset();
2646+
int pEndOffset = lineOffset + (stopOffset == -1 ? 0 : stopOffset);
26352647
int pEndLine = textarea.getLineOfOffset(pEndOffset);
26362648

26372649
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: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ 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+
return new Offset(before.line, Integer.MAX_VALUE);
116+
}
117+
113118

114119
/**
115120
* Converts a tabOffset to a position within a tab
@@ -232,21 +237,32 @@ void updateProblems(List<Problem> problems) {
232237
int startOffset = prob.getStartOffset();
233238
int endOffset = prob.getStopOffset();
234239

240+
Position startPosition = new Position(
241+
prob.getLineNumber(),
242+
PdeAdapter
243+
.toLineCol(code.getProgram(), startOffset)
244+
.col - 1
245+
);
246+
247+
Position stopPosition;
248+
if (endOffset == -1) {
249+
stopPosition = new Position(
250+
prob.getLineNumber(),
251+
PdeAdapter
252+
.toLineEndCol(code.getProgram(), startOffset)
253+
.col - 1
254+
);
255+
} else {
256+
stopPosition = new Position(
257+
prob.getLineNumber(),
258+
PdeAdapter
259+
.toLineCol(code.getProgram(), endOffset)
260+
.col - 1
261+
);
262+
}
263+
235264
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-
),
265+
new Range(startPosition, stopPosition),
250266
prob.getMessage()
251267
);
252268
dia.setSeverity(

0 commit comments

Comments
 (0)