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
58 changes: 4 additions & 54 deletions app/src/processing/app/Problem.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@
*/
public interface Problem {

/**
* Strategy converting line number in tab to character offset from tab start.
*/
public interface LineToTabOffsetGetter {

/**
* Convert a line number to the number of characters past tab start.
*
* @param line The line number to convert.
* @return The number of characters past tab start where that line starts.
*/
public int get(int line);

}

/**
* Get if the problem is an error that prevented compilation.
*
Expand Down Expand Up @@ -81,56 +66,21 @@ public interface LineToTabOffsetGetter {
*/
public String getMessage();

/**
* Get the exact character on which this problem starts in code tab relative.
*
* @return Number of characters past the start of the tab if known where the
* code associated with the Problem starts. Returns empty if not provided.
*/
public Optional<Integer> getTabStartOffset();

/**
* Get the exact character on which this problem ends in code tab relative.
*
* @return Number of characters past the start of the tab if known where the
* code associated with the Problem ends. Returns empty if not provided.
*/
public Optional<Integer> getTabStopOffset();

/**
* Get the exact character on which this problem starts in code line relative.
*
* @return Number of characters past the start of the line if known where the
* code associated with the Problem starts. Returns empty if not provided.
* code associated with the Problem starts.
*/
public Optional<Integer> getLineStartOffset();
public int getStartOffset();

/**
* 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. Returns empty if not provided.
*/
public Optional<Integer> getLineStopOffset();

/**
* Get the exact character on which this problem ends in code tab relative.
*
* @param strategy Strategy to convert line to tab start if needed.
* @return Number of characters past the start of the tab if known where the
* code associated with the Problem ends, using the provided conversion
* if needed. Returns line start if character position not given.
* code associated with the Problem ends.
*/
public int computeTabStartOffset(LineToTabOffsetGetter strategy);
public int getStopOffset();

/**
* Get the exact character on which this problem ends in code tab relative.
*
* @param strategy Strategy to convert line to tab start if needed.
* @return Number of characters past the start of the tab if known where the
* code associated with the Problem ends, using the provided conversion
* if needed. Returns line start if character position not given.
*/
public int computeTabStopOffset(LineToTabOffsetGetter strategy);
}

17 changes: 4 additions & 13 deletions app/src/processing/app/syntax/PdeTextAreaPainter.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ public class PdeTextAreaPainter extends TextAreaPainter {
protected Color gutterTextInactiveColor;
protected Color gutterHighlightColor;

private final Problem.LineToTabOffsetGetter lineToTabOffsetGetter;


public PdeTextAreaPainter(JEditTextArea textArea, TextAreaDefaults defaults) {
super(textArea, defaults);
Expand Down Expand Up @@ -78,10 +76,6 @@ public void mousePressed(MouseEvent event) {
}
}
});

lineToTabOffsetGetter = (x) -> {
return textArea.getLineStartOffset(x);
};
}


Expand Down Expand Up @@ -153,14 +147,11 @@ protected void paintLine(Graphics gfx, int line, int x, TokenMarkerState marker)
protected void paintErrorLine(Graphics gfx, int line, int x) {
List<Problem> problems = getEditor().findProblems(line);
for (Problem problem : problems) {
int startOffset = problem.computeTabStartOffset(lineToTabOffsetGetter);
int stopOffset = problem.computeTabStopOffset(lineToTabOffsetGetter);

int lineOffsetStart = textArea.getLineStartOffset(line);
int lineOffsetStop = textArea.getLineStopOffset(line);

int wiggleStart = Math.max(startOffset, lineOffsetStart);
int wiggleStop = Math.min(stopOffset, lineOffsetStop);
int wiggleStart = lineOffsetStart + problem.getStartOffset();
int wiggleStop = lineOffsetStart + problem.getStopOffset();

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

Expand Down Expand Up @@ -338,8 +329,8 @@ public String getToolTipText(MouseEvent event) {
int lineStart = textArea.getLineStartOffset(line);
int lineEnd = textArea.getLineStopOffset(line);

int errorStart = problem.computeTabStartOffset(lineToTabOffsetGetter);
int errorEnd = problem.computeTabStopOffset(lineToTabOffsetGetter) + 1;
int errorStart = lineStart + problem.getStartOffset();
int errorEnd = lineStart + problem.getStopOffset();

int startOffset = Math.max(errorStart, lineStart) - lineStart;
int stopOffset = Math.min(errorEnd, lineEnd) - lineStart;
Expand Down
25 changes: 12 additions & 13 deletions app/src/processing/app/ui/Editor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2556,16 +2556,16 @@ public void updateErrorTable(List<Problem> problems) {


public void highlight(Problem p) {
Problem.LineToTabOffsetGetter getter = (x) -> {
return textarea.getLineStartOffset(x);
};

if (p != null) {
int tabIndex = p.getTabIndex();
int tabToStartOffset = p.computeTabStartOffset(getter);
int tabToStopOffset = p.computeTabStopOffset(getter);
highlight(tabIndex, tabToStartOffset, tabToStopOffset);
if (p == null) {
return;
}

int tabIndex = p.getTabIndex();
int lineNumber = p.getLineNumber();
int lineStart = textarea.getLineStartOffset(lineNumber);
int tabToStartOffset = lineStart + p.getStartOffset();
int tabToStopOffset = lineStart + p.getStopOffset();
highlight(tabIndex, tabToStartOffset, tabToStopOffset);
}


Expand Down Expand Up @@ -2630,11 +2630,10 @@ public List<Problem> findProblems(int line) {
.filter(p -> p.getTabIndex() == currentTab)
.filter(p -> {
int pStartLine = p.getLineNumber();
int pEndOffset = p.computeTabStopOffset(
(startLine) -> textarea.getLineStartOffset(pStartLine)
);
int lineOffset = textarea.getLineStartOffset(pStartLine);
int pEndOffset = lineOffset + p.getStopOffset();
int pEndLine = textarea.getLineOfOffset(pEndOffset);

return line >= pStartLine && line <= pEndLine;
})
.collect(Collectors.toList());
Expand Down
4 changes: 1 addition & 3 deletions 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(in.startTabOffset, in.stopTabOffset);
p.setPDEOffsets(0, iproblem.getSourceEnd() - iproblem.getSourceStart());
return p;
}
return null;
Expand Down Expand Up @@ -252,7 +252,6 @@ static private List<JavaProblem> checkForCurlyQuotes(PreprocSketch ps) {

String message = Language.interpolate("editor.status.bad_curly_quote", q);
JavaProblem problem = new JavaProblem(message, JavaProblem.ERROR, tabIndex, tabLine);
problem.setPDEOffsets(tabOffset, tabOffset+1);

problems.add(problem);
}
Expand Down Expand Up @@ -294,7 +293,6 @@ static private List<JavaProblem> checkForCurlyQuotes(PreprocSketch ps) {
message = Language.interpolate("editor.status.bad_curly_quote", q);
}
JavaProblem p = new JavaProblem(message, JavaProblem.ERROR, in.tabIndex, line);
p.setPDEOffsets(tabStart, tabStop);
problems2.add(p);
}
}
Expand Down
62 changes: 10 additions & 52 deletions java/src/processing/mode/java/JavaProblem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

package processing.mode.java;

import java.util.Optional;

import org.eclipse.jdt.core.compiler.IProblem;

import processing.app.Problem;
Expand All @@ -44,9 +42,9 @@ public class JavaProblem implements Problem {
/** Line number (pde code) of the error */
private final int lineNumber;

private Optional<Integer> startOffset;
private int startOffset;

private Optional<Integer> stopOffset;
private int stopOffset;

/**
* If the error is a 'cannot find type' contains the list of suggested imports
Expand All @@ -62,8 +60,10 @@ public JavaProblem(String message, int type, int tabIndex, int lineNumber) {
this.type = type;
this.tabIndex = tabIndex;
this.lineNumber = lineNumber;
this.startOffset = Optional.empty();
this.stopOffset = Optional.empty();

// Default to 0, 1 unless a longer section is specified
this.startOffset = 0;
this.stopOffset = 1;
}


Expand All @@ -87,32 +87,22 @@ static public JavaProblem fromIProblem(IProblem iProblem, int tabIndex,


public void setPDEOffsets(int startOffset, int stopOffset){
this.startOffset = Optional.of(startOffset);
this.stopOffset = Optional.of(stopOffset);
this.startOffset = startOffset;
this.stopOffset = stopOffset;
}


@Override
public Optional<Integer> getTabStartOffset() {
public int getStartOffset() {
return startOffset;
}


@Override
public Optional<Integer> getTabStopOffset() {
public int getStopOffset() {
return stopOffset;
}

@Override
public Optional<Integer> getLineStartOffset() {
return Optional.empty();
}

@Override
public Optional<Integer> getLineStopOffset() {
return Optional.empty();
}

@Override
public boolean isError() {
return type == ERROR;
Expand Down Expand Up @@ -163,36 +153,4 @@ public String toString() {
+ message;
}

@Override
public int computeTabStartOffset(LineToTabOffsetGetter strategy) {
Optional<Integer> nativeTabStartOffset = getTabStartOffset();
if (nativeTabStartOffset.isPresent()) {
return nativeTabStartOffset.get();
}

Optional<Integer> lineStartOffset = getLineStartOffset();
int lineOffset = strategy.get(getLineNumber());
if (lineStartOffset.isPresent()) {
return lineOffset + lineStartOffset.get();
} else {
return lineOffset;
}
}

@Override
public int computeTabStopOffset(LineToTabOffsetGetter strategy) {
Optional<Integer> nativeTabStopOffset = getTabStopOffset();
if (nativeTabStopOffset.isPresent()) {
return nativeTabStopOffset.get();
}

Optional<Integer> lineStopOffset = getLineStopOffset();
int lineOffset = strategy.get(getLineNumber());
if (lineStopOffset.isPresent()) {
return lineOffset + lineStopOffset.get();
} else {
return lineOffset;
}
}

}
8 changes: 5 additions & 3 deletions java/src/processing/mode/java/PreprocService.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class PreprocService {
}};

/**
* Create a new preprocessing service to support an editor.
* Create a new preprocessing service to support the language server.
*/
public PreprocService(JavaMode javaMode, Sketch sketch) {
this.javaMode = javaMode;
Expand Down Expand Up @@ -411,10 +411,12 @@ private PreprocSketch preprocessSketch(PreprocSketch prevResult) {
throw new RuntimeException("Unexpected sketch exception in preprocessing: " + e);
}

final int endNumLines = numLines;

if (preprocessorResult.getPreprocessIssues().size() > 0) {
preprocessorResult.getPreprocessIssues().stream()
.map((x) -> ProblemFactory.build(x, tabLineStarts))
.forEach(result.otherProblems::add);
.map((x) -> ProblemFactory.build(x, tabLineStarts))
.forEach(result.otherProblems::add);

result.hasSyntaxErrors = true;
}
Expand Down
47 changes: 1 addition & 46 deletions java/src/processing/mode/java/ProblemFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,6 @@
*/
public class ProblemFactory {

/**
* Create a new {Problem}.
*
* @param pdePreprocessIssue The preprocess issue found.
* @param tabStarts The list of line numbers on which each tab starts.
* @param editor The editor in which errors will appear.
* @return Newly created problem.
*/
public static Problem build(PdePreprocessIssue pdePreprocessIssue, List<Integer> tabStarts,
int numLines, Editor editor) {

int line = pdePreprocessIssue.getLine();

// Sometimes errors are reported one line past end of sketch. Fix that.
if (line >= numLines) {
line = numLines - 1;
}

// Get local area
TabLine tabLine = getTab(tabStarts, line);

int tab = tabLine.getTab();
int localLine = tabLine.getLineInTab(); // Problems emitted in 0 index

// Generate syntax problem
String message = pdePreprocessIssue.getMsg();

int lineStart = editor.getLineStartOffset(localLine);
int lineStop = editor.getLineStopOffset(localLine) - 1;

if (lineStart == lineStop) {
lineStop++;
}

return new SyntaxProblem(
tab,
localLine,
message,
lineStart,
lineStop,
false
);
}

/**
* Create a new {Problem}.
*
Expand Down Expand Up @@ -85,8 +41,7 @@ public static Problem build(PdePreprocessIssue pdePreprocessIssue, List<Integer>
localLine,
message,
0,
col,
true
col
);
}

Expand Down
Loading