CLI: improve diagnostic message format

- render the whole line where the error/warning points to, if any, and another
  line with '^', like other compilers do
- lowercase diagnostic severity
- decapitalize the message if it doesn't start with a proper name
This commit is contained in:
Alexander Udalov
2015-06-13 03:43:20 +03:00
parent 46515afb22
commit 54dfd626ab
49 changed files with 316 additions and 134 deletions
@@ -128,16 +128,19 @@ public class DiagnosticUtils {
}
@NotNull
public static LineAndColumn offsetToLineAndColumn(Document document, int offset) {
public static LineAndColumn offsetToLineAndColumn(@Nullable Document document, int offset) {
if (document == null) {
return new LineAndColumn(-1, offset);
return new LineAndColumn(-1, offset, null);
}
int lineNumber = document.getLineNumber(offset);
int lineStartOffset = document.getLineStartOffset(lineNumber);
int column = offset - lineStartOffset;
return new LineAndColumn(lineNumber + 1, column + 1);
int lineEndOffset = document.getLineEndOffset(lineNumber);
CharSequence lineContent = document.getCharsSequence().subSequence(lineStartOffset, lineEndOffset);
return new LineAndColumn(lineNumber + 1, column + 1, lineContent.toString());
}
public static void throwIfRunningOnServer(Throwable e) {
@@ -184,14 +187,16 @@ public class DiagnosticUtils {
public static final class LineAndColumn {
public static final LineAndColumn NONE = new LineAndColumn(-1, -1);
public static final LineAndColumn NONE = new LineAndColumn(-1, -1, null);
private final int line;
private final int column;
private final String lineContent;
public LineAndColumn(int line, int column) {
public LineAndColumn(int line, int column, @Nullable String lineContent) {
this.line = line;
this.column = column;
this.lineContent = lineContent;
}
public int getLine() {
@@ -202,6 +207,11 @@ public class DiagnosticUtils {
return column;
}
@Nullable
public String getLineContent() {
return lineContent;
}
// NOTE: This method is used for presenting positions to the user
@Override
public String toString() {