Add info about the end of range in scripting REPL compiler messages

This commit is contained in:
Ilya Muradyan
2020-02-12 16:57:52 +01:00
committed by Ilya Chernikov
parent 5e33612238
commit 489290263f
9 changed files with 119 additions and 17 deletions
@@ -22,6 +22,8 @@ interface CompilerMessageSourceLocation : Serializable {
val path: String
val line: Int
val column: Int
val lineEnd: Int get() = -1
val columnEnd: Int get() = -1
val lineContent: String?
}
@@ -46,3 +48,31 @@ data class CompilerMessageLocation private constructor(
private val serialVersionUID: Long = 8228357578L
}
}
data class CompilerMessageLocationWithRange private constructor(
override val path: String,
override val line: Int,
override val column: Int,
override val lineEnd: Int,
override val columnEnd: Int,
override val lineContent: String?
) : CompilerMessageSourceLocation {
override fun toString(): String =
path + (if (line != -1 || column != -1) " ($line:$column)" else "")
companion object {
@JvmStatic
fun create(
path: String?,
lineStart: Int,
columnStart: Int,
lineEnd: Int?,
columnEnd: Int?,
lineContent: String?
): CompilerMessageLocationWithRange? =
if (path == null) null else CompilerMessageLocationWithRange(path, lineStart, columnStart, lineEnd ?: -1, columnEnd ?: -1, lineContent)
private val serialVersionUID: Long = 8228357578L
}
}
@@ -31,6 +31,6 @@ interface MessageCollectorBasedReporter : DiagnosticMessageReporter {
override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) = messageCollector.report(
AnalyzerWithCompilerReport.convertSeverity(diagnostic.severity),
render,
MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumn(diagnostic))
MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumnRange(diagnostic))
)
}
@@ -32,21 +32,23 @@ public class MessageUtil {
private MessageUtil() {}
@Nullable
public static CompilerMessageLocation psiElementToMessageLocation(@Nullable PsiElement element) {
public static CompilerMessageSourceLocation psiElementToMessageLocation(@Nullable PsiElement element) {
if (element == null) return null;
PsiFile file = element.getContainingFile();
return psiFileToMessageLocation(file, "<no path>", DiagnosticUtils.getLineAndColumnInPsiFile(file, element.getTextRange()));
return psiFileToMessageLocation(file, "<no path>", DiagnosticUtils.getLineAndColumnRangeInPsiFile(file, element.getTextRange()));
}
@Nullable
public static CompilerMessageLocation psiFileToMessageLocation(
public static CompilerMessageSourceLocation psiFileToMessageLocation(
@NotNull PsiFile file,
@Nullable String defaultValue,
@NotNull PsiDiagnosticUtils.LineAndColumn lineAndColumn
@NotNull PsiDiagnosticUtils.LineAndColumnRange range
) {
VirtualFile virtualFile = file.getVirtualFile();
String path = virtualFile != null ? virtualFileToPath(virtualFile) : defaultValue;
return CompilerMessageLocation.create(path, lineAndColumn.getLine(), lineAndColumn.getColumn(), lineAndColumn.getLineContent());
PsiDiagnosticUtils.LineAndColumn start = range.getStart();
PsiDiagnosticUtils.LineAndColumn end = range.getEnd();
return CompilerMessageLocationWithRange.create(path, start.getLine(), start.getColumn(), end.getLine(), end.getColumn(), start.getLineContent());
}
@NotNull