diff --git a/app/src/processing/app/Problem.java b/app/src/processing/app/Problem.java index 6a0faf380..54a5f5391 100644 --- a/app/src/processing/app/Problem.java +++ b/app/src/processing/app/Problem.java @@ -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(); diff --git a/app/src/processing/app/syntax/PdeTextAreaPainter.java b/app/src/processing/app/syntax/PdeTextAreaPainter.java index 2c83a518b..a19fcba58 100644 --- a/app/src/processing/app/syntax/PdeTextAreaPainter.java +++ b/app/src/processing/app/syntax/PdeTextAreaPainter.java @@ -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(); @@ -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; diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index 911df7a49..3babbb6df 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -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; + } + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . @@ -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); } @@ -2631,7 +2642,8 @@ public List 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; diff --git a/java/src/processing/mode/java/ErrorChecker.java b/java/src/processing/mode/java/ErrorChecker.java index e631fbd4f..512d71d57 100644 --- a/java/src/processing/mode/java/ErrorChecker.java +++ b/java/src/processing/mode/java/ErrorChecker.java @@ -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; diff --git a/java/src/processing/mode/java/lsp/PdeAdapter.java b/java/src/processing/mode/java/lsp/PdeAdapter.java index 1a58f3c8e..f4f1f450d 100644 --- a/java/src/processing/mode/java/lsp/PdeAdapter.java +++ b/java/src/processing/mode/java/lsp/PdeAdapter.java @@ -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 @@ -232,21 +237,32 @@ void updateProblems(List 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(