From 490fc2bfee426ef6fd890f6944579f4f33b7d54f Mon Sep 17 00:00:00 2001 From: Sam Pottinger Date: Wed, 10 May 2023 16:13:37 -0700 Subject: [PATCH] Closes #714. Depending on how the Problem is made, the error may be given relative to start of line or start of tab. Flag indicates to users of Problems which one they are working with. --- app/src/processing/app/Problem.java | 2 +- .../processing/app/syntax/PdeTextAreaPainter.java | 5 +++++ app/src/processing/app/ui/Editor.java | 10 +++++++++- java/src/processing/mode/java/JavaProblem.java | 5 ++++- java/src/processing/mode/java/ProblemFactory.java | 8 +++++--- java/src/processing/mode/java/SyntaxProblem.java | 14 +++++++++++--- 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/app/src/processing/app/Problem.java b/app/src/processing/app/Problem.java index cb12ad5e3..e271836c9 100644 --- a/app/src/processing/app/Problem.java +++ b/app/src/processing/app/Problem.java @@ -17,7 +17,6 @@ along with this program; if not, write to the Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ - package processing.app; @@ -29,6 +28,7 @@ public interface Problem { public int getLineNumber(); // 0-indexed public String getMessage(); + public boolean isLineOffset(); public int getStartOffset(); public int getStopOffset(); } diff --git a/app/src/processing/app/syntax/PdeTextAreaPainter.java b/app/src/processing/app/syntax/PdeTextAreaPainter.java index ef517a9d2..8b3fb37d8 100644 --- a/app/src/processing/app/syntax/PdeTextAreaPainter.java +++ b/app/src/processing/app/syntax/PdeTextAreaPainter.java @@ -152,6 +152,11 @@ public class PdeTextAreaPainter extends TextAreaPainter { int lineOffset = textArea.getLineStartOffset(line); + if (problem.isLineOffset()) { + startOffset += lineOffset; + stopOffset += lineOffset; + } + int wiggleStart = Math.max(startOffset, lineOffset); int wiggleStop = Math.min(stopOffset, textArea.getLineStopOffset(line)); diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index b9761aa79..77f1bb7b1 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -2624,7 +2624,15 @@ public abstract class Editor extends JFrame implements RunnerListener { .filter(p -> { int pStartLine = p.getLineNumber(); int pEndOffset = p.getStopOffset(); - int pEndLine = textarea.getLineOfOffset(pEndOffset); + + int pEndLine; + if (p.isLineOffset()) { + int lineGlobalOffset = textarea.getLineStartOffset(pStartLine); + pEndLine = textarea.getLineOfOffset(pEndOffset + lineGlobalOffset); + } else { + pEndLine = textarea.getLineOfOffset(pEndOffset); + } + return line >= pStartLine && line <= pEndLine; }) .collect(Collectors.toList()); diff --git a/java/src/processing/mode/java/JavaProblem.java b/java/src/processing/mode/java/JavaProblem.java index 232063d2f..687926085 100644 --- a/java/src/processing/mode/java/JavaProblem.java +++ b/java/src/processing/mode/java/JavaProblem.java @@ -82,7 +82,7 @@ public class JavaProblem implements Problem { } - public void setPDEOffsets(int startOffset, int stopOffset){ + public void setPDEOffsets(int startOffset, int stopOffset) { this.startOffset = startOffset; this.stopOffset = stopOffset; } @@ -139,6 +139,9 @@ public class JavaProblem implements Problem { importSuggestions = a; } + public boolean isLineOffset() { + return false; + } @Override public String toString() { diff --git a/java/src/processing/mode/java/ProblemFactory.java b/java/src/processing/mode/java/ProblemFactory.java index e7ec06729..ce5cbff63 100644 --- a/java/src/processing/mode/java/ProblemFactory.java +++ b/java/src/processing/mode/java/ProblemFactory.java @@ -53,7 +53,8 @@ public class ProblemFactory { localLine, message, lineStart, - lineStop + lineStop, + false ); } @@ -83,8 +84,9 @@ public class ProblemFactory { tab, localLine, message, - localLine, - localLine + col + 0, + col, + true ); } diff --git a/java/src/processing/mode/java/SyntaxProblem.java b/java/src/processing/mode/java/SyntaxProblem.java index 14b9e9262..b0f8d97df 100644 --- a/java/src/processing/mode/java/SyntaxProblem.java +++ b/java/src/processing/mode/java/SyntaxProblem.java @@ -10,6 +10,7 @@ public class SyntaxProblem extends JavaProblem { private final String message; private final int startOffset; private final int stopOffset; + private final boolean lineFlag; /** * Create a new syntax problem. @@ -18,12 +19,14 @@ public class SyntaxProblem extends JavaProblem { * @param newLineNumber The line number within the tab at which the offending code can be found. * @param newMessage Human readable message describing the issue. * @param newStartOffset The character index at which the issue starts. This is relative to start - * of tab / file not relative to start of line. + * of tab / file not relative to start of line if newIsLineOffset is true else it is line + * offset. * @param newStopOffset The character index at which the issue ends. This is relative to start - * * of tab / file not relative to start of line. + * of tab / file not relative to start of line if newIsLineOffset is true else it is line + * offset. */ public SyntaxProblem(int newTabIndex, int newLineNumber, String newMessage, int newStartOffset, - int newStopOffset) { + int newStopOffset, boolean newIsLineOffset) { super(newMessage, JavaProblem.ERROR, newLineNumber, newLineNumber); @@ -32,6 +35,7 @@ public class SyntaxProblem extends JavaProblem { message = newMessage; startOffset = newStartOffset; stopOffset = newStopOffset; + lineFlag = newIsLineOffset; } @Override @@ -69,4 +73,8 @@ public class SyntaxProblem extends JavaProblem { return stopOffset; } + public boolean isLineOffset() { + return lineFlag; + } + }