Skip to content

Commit d8e5652

Browse files
cmagliefacchinm
authored andcommitted
Output column info from compiler error when available
1 parent d6bc327 commit d8e5652

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

Diff for: arduino-core/src/cc/arduino/Compiler.java

+20-5
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,17 @@ public void message(String s) {
545545
String[] pieces = PApplet.match(s, ERROR_FORMAT);
546546

547547
if (pieces != null) {
548-
String error = pieces[pieces.length - 1], msg = "";
548+
String msg = "";
549+
int errorIdx = pieces.length - 1;
550+
String error = pieces[errorIdx];
551+
String filename = pieces[1];
552+
int line = PApplet.parseInt(pieces[2]);
553+
int col;
554+
if (errorIdx > 3) {
555+
col = PApplet.parseInt(pieces[3].substring(1));
556+
} else {
557+
col = -1;
558+
}
549559

550560
if (error.trim().equals("SPI.h: No such file or directory")) {
551561
error = tr("Please import the SPI library from the Sketch > Import Library menu.");
@@ -599,12 +609,17 @@ public void message(String s) {
599609
//msg = _("\nThe 'Keyboard' class is only supported on the Arduino Leonardo.\n\n");
600610
}
601611

602-
RunnerException ex = placeException(error, pieces[1], PApplet.parseInt(pieces[2]) - 1);
612+
RunnerException ex = placeException(error, filename, line - 1, col);
603613

604614
if (ex != null) {
605615
String fileName = ex.getCodeFile().getPrettyName();
606616
int lineNum = ex.getCodeLine() + 1;
607-
s = fileName + ":" + lineNum + ": error: " + error + msg;
617+
int colNum = ex.getCodeColumn();
618+
if (colNum != -1) {
619+
s = fileName + ":" + lineNum + ":" + colNum + ": error: " + error + msg;
620+
} else {
621+
s = fileName + ":" + lineNum + ": error: " + error + msg;
622+
}
608623
}
609624

610625
if (ex != null) {
@@ -630,10 +645,10 @@ public void message(String s) {
630645
System.err.println(s);
631646
}
632647

633-
private RunnerException placeException(String message, String fileName, int line) {
648+
private RunnerException placeException(String message, String fileName, int line, int col) {
634649
for (SketchFile file : sketch.getFiles()) {
635650
if (new File(fileName).getName().equals(file.getFileName())) {
636-
return new RunnerException(message, file, line);
651+
return new RunnerException(message, file, line, col);
637652
}
638653
}
639654
return null;

0 commit comments

Comments
 (0)