Skip to content
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
2 changes: 1 addition & 1 deletion app/src/processing/app/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public interface Problem {
* Get the exact character on which this problem ends in code line relative.
*
* @return Number of characters past the start of the line if known where the
* code associated with the Problem ends.
* code associated with the Problem ends. If -1, should use the whole line.
*/
public int getStopOffset();

Expand Down
6 changes: 4 additions & 2 deletions app/src/processing/app/syntax/PdeTextAreaPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ protected void paintErrorLine(Graphics gfx, int line, int x) {
int lineOffsetStop = textArea.getLineStopOffset(line);

int wiggleStart = lineOffsetStart + problem.getStartOffset();
int wiggleStop = lineOffsetStart + problem.getStopOffset();
int stopOffset = Editor.getProblemEditorLineStop(problem, lineOffsetStart, lineOffsetStop);
int wiggleStop = lineOffsetStart + stopOffset;

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

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

int errorStart = lineStart + problem.getStartOffset();
int errorEnd = lineStart + problem.getStopOffset();
int stopOffsetLine = Editor.getProblemEditorLineStop(problem, lineStart, lineEnd);
int errorEnd = lineStart + stopOffsetLine;

int startOffset = Math.max(errorStart, lineStart) - lineStart;
int stopOffset = Math.min(errorEnd, lineEnd) - lineStart;
Expand Down
16 changes: 14 additions & 2 deletions app/src/processing/app/ui/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,14 @@ static public void showChanges() {
}
}

static public int getProblemEditorLineStop(Problem problem, int lineStart, int lineStop) {
int stopOffset = problem.getStopOffset();
if (stopOffset == -1) {
stopOffset = lineStop - lineStart;
}
return stopOffset;
}


// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Expand Down Expand Up @@ -2563,8 +2571,11 @@ public void highlight(Problem p) {
int tabIndex = p.getTabIndex();
int lineNumber = p.getLineNumber();
int lineStart = textarea.getLineStartOffset(lineNumber);
int lineEnd = textarea.getLineStopOffset(lineNumber);
int tabToStartOffset = lineStart + p.getStartOffset();
int tabToStopOffset = lineStart + p.getStopOffset();

int lineStopOffset = getProblemEditorLineStop(p, lineStart, lineEnd);
int tabToStopOffset = lineStart + lineStopOffset;
highlight(tabIndex, tabToStartOffset, tabToStopOffset);
}

Expand Down Expand Up @@ -2631,7 +2642,8 @@ public List<Problem> findProblems(int line) {
.filter(p -> {
int pStartLine = p.getLineNumber();
int lineOffset = textarea.getLineStartOffset(pStartLine);
int pEndOffset = lineOffset + p.getStopOffset();
int stopOffset = p.getStopOffset();
int pEndOffset = lineOffset + (stopOffset == -1 ? 0 : stopOffset);
int pEndLine = textarea.getLineOfOffset(pEndOffset);

return line >= pStartLine && line <= pEndLine;
Expand Down
2 changes: 1 addition & 1 deletion java/src/processing/mode/java/ErrorChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ static private JavaProblem convertIProblem(IProblem iproblem, PreprocSketch ps)
String badCode = ps.getPdeCode(in);
int line = ps.tabOffsetToTabLine(in.tabIndex, in.startTabOffset);
JavaProblem p = JavaProblem.fromIProblem(iproblem, in.tabIndex, line, badCode);
p.setPDEOffsets(0, iproblem.getSourceEnd() - iproblem.getSourceStart());
p.setPDEOffsets(0, -1);
return p;
}
return null;
Expand Down
44 changes: 30 additions & 14 deletions java/src/processing/mode/java/lsp/PdeAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ static Offset toLineCol(String s, int offset) {
return new Offset(line, col);
}

static Offset toLineEndCol(String s, int offset) {
Offset before = toLineCol(s, offset);
return new Offset(before.line, Integer.MAX_VALUE);
}


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

Position startPosition = new Position(
prob.getLineNumber(),
PdeAdapter
.toLineCol(code.getProgram(), startOffset)
.col - 1
);

Position stopPosition;
if (endOffset == -1) {
stopPosition = new Position(
prob.getLineNumber(),
PdeAdapter
.toLineEndCol(code.getProgram(), startOffset)
.col - 1
);
} else {
stopPosition = new Position(
prob.getLineNumber(),
PdeAdapter
.toLineCol(code.getProgram(), endOffset)
.col - 1
);
}

Diagnostic dia = new Diagnostic(
new Range(
new Position(
prob.getLineNumber(),
PdeAdapter
.toLineCol(code.getProgram(), startOffset)
.col - 1
),
new Position(
prob.getLineNumber(),
PdeAdapter
.toLineCol(code.getProgram(), endOffset)
.col - 1
)
),
new Range(startPosition, stopPosition),
prob.getMessage()
);
dia.setSeverity(
Expand Down