Revert "Add info about the end of range in scripting REPL compiler messages"
This reverts commit af251caf, because it breaks daemon/client
compatibility, which we'd like to keep as much as possible
This commit is contained in:
+7
-20
@@ -19,12 +19,10 @@ package org.jetbrains.kotlin.cli.common.messages
|
|||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
|
|
||||||
data class CompilerMessageLocation private constructor(
|
data class CompilerMessageLocation private constructor(
|
||||||
val path: String,
|
val path: String,
|
||||||
val line: Int,
|
val line: Int,
|
||||||
val column: Int,
|
val column: Int,
|
||||||
val lineEnd: Int,
|
val lineContent: String?
|
||||||
val columnEnd: Int,
|
|
||||||
val lineContent: String?
|
|
||||||
) : Serializable {
|
) : Serializable {
|
||||||
override fun toString(): String =
|
override fun toString(): String =
|
||||||
path + (if (line != -1 || column != -1) " ($line:$column)" else "")
|
path + (if (line != -1 || column != -1) " ($line:$column)" else "")
|
||||||
@@ -32,23 +30,12 @@ data class CompilerMessageLocation private constructor(
|
|||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun create(path: String?): CompilerMessageLocation? =
|
fun create(path: String?): CompilerMessageLocation? =
|
||||||
create(path, -1, -1, null)
|
create(path, -1, -1, null)
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun create(path: String?, line: Int, column: Int, lineContent: String?): CompilerMessageLocation? =
|
fun create(path: String?, line: Int, column: Int, lineContent: String?): CompilerMessageLocation? =
|
||||||
if (path == null) null else CompilerMessageLocation(path, line, column, -1, -1, lineContent)
|
if (path == null) null else CompilerMessageLocation(path, line, column, lineContent)
|
||||||
|
|
||||||
@JvmStatic
|
private val serialVersionUID: Long = 8228357578L
|
||||||
fun create(
|
|
||||||
path: String?,
|
|
||||||
lineStart: Int,
|
|
||||||
columnStart: Int,
|
|
||||||
lineEnd: Int?,
|
|
||||||
columnEnd: Int?,
|
|
||||||
lineContent: String?
|
|
||||||
): CompilerMessageLocation? =
|
|
||||||
if (path == null) null else CompilerMessageLocation(path, lineStart, columnStart, lineEnd ?: -1, columnEnd ?: -1, lineContent)
|
|
||||||
|
|
||||||
private val serialVersionUID: Long = 8228357579L
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -31,6 +31,6 @@ interface MessageCollectorBasedReporter : DiagnosticMessageReporter {
|
|||||||
override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) = messageCollector.report(
|
override fun report(diagnostic: Diagnostic, file: PsiFile, render: String) = messageCollector.report(
|
||||||
AnalyzerWithCompilerReport.convertSeverity(diagnostic.severity),
|
AnalyzerWithCompilerReport.convertSeverity(diagnostic.severity),
|
||||||
render,
|
render,
|
||||||
MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumnRange(diagnostic))
|
MessageUtil.psiFileToMessageLocation(file, file.name, DiagnosticUtils.getLineAndColumn(diagnostic))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,20 +35,18 @@ public class MessageUtil {
|
|||||||
public static CompilerMessageLocation psiElementToMessageLocation(@Nullable PsiElement element) {
|
public static CompilerMessageLocation psiElementToMessageLocation(@Nullable PsiElement element) {
|
||||||
if (element == null) return null;
|
if (element == null) return null;
|
||||||
PsiFile file = element.getContainingFile();
|
PsiFile file = element.getContainingFile();
|
||||||
return psiFileToMessageLocation(file, "<no path>", DiagnosticUtils.getLineAndColumnRangeInPsiFile(file, element.getTextRange()));
|
return psiFileToMessageLocation(file, "<no path>", DiagnosticUtils.getLineAndColumnInPsiFile(file, element.getTextRange()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static CompilerMessageLocation psiFileToMessageLocation(
|
public static CompilerMessageLocation psiFileToMessageLocation(
|
||||||
@NotNull PsiFile file,
|
@NotNull PsiFile file,
|
||||||
@Nullable String defaultValue,
|
@Nullable String defaultValue,
|
||||||
@NotNull PsiDiagnosticUtils.LineAndColumnRange range
|
@NotNull PsiDiagnosticUtils.LineAndColumn lineAndColumn
|
||||||
) {
|
) {
|
||||||
VirtualFile virtualFile = file.getVirtualFile();
|
VirtualFile virtualFile = file.getVirtualFile();
|
||||||
String path = virtualFile != null ? virtualFileToPath(virtualFile) : defaultValue;
|
String path = virtualFile != null ? virtualFileToPath(virtualFile) : defaultValue;
|
||||||
PsiDiagnosticUtils.LineAndColumn start = range.getStart();
|
return CompilerMessageLocation.create(path, lineAndColumn.getLine(), lineAndColumn.getColumn(), lineAndColumn.getLineContent());
|
||||||
PsiDiagnosticUtils.LineAndColumn end = range.getEnd();
|
|
||||||
return CompilerMessageLocation.create(path, start.getLine(), start.getColumn(), end.getLine(), end.getColumn(), start.getLineContent());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|||||||
@@ -84,24 +84,6 @@ public class DiagnosticUtils {
|
|||||||
return PsiDiagnosticUtils.offsetToLineAndColumn(document, range.getStartOffset());
|
return PsiDiagnosticUtils.offsetToLineAndColumn(document, range.getStartOffset());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static PsiDiagnosticUtils.LineAndColumnRange getLineAndColumnRange(@NotNull Diagnostic diagnostic) {
|
|
||||||
PsiFile file = diagnostic.getPsiFile();
|
|
||||||
List<TextRange> textRanges = diagnostic.getTextRanges();
|
|
||||||
if (textRanges.isEmpty()) return PsiDiagnosticUtils.LineAndColumnRange.NONE;
|
|
||||||
TextRange firstRange = firstRange(textRanges);
|
|
||||||
return getLineAndColumnRangeInPsiFile(file, firstRange);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static PsiDiagnosticUtils.LineAndColumnRange getLineAndColumnRangeInPsiFile(PsiFile file, TextRange range) {
|
|
||||||
Document document = file.getViewProvider().getDocument();
|
|
||||||
return new PsiDiagnosticUtils.LineAndColumnRange(
|
|
||||||
PsiDiagnosticUtils.offsetToLineAndColumn(document, range.getStartOffset()),
|
|
||||||
PsiDiagnosticUtils.offsetToLineAndColumn(document, range.getEndOffset())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void throwIfRunningOnServer(Throwable e) {
|
public static void throwIfRunningOnServer(Throwable e) {
|
||||||
// This is needed for the Web Demo server to log the exceptions coming from the analyzer instead of showing them in the editor.
|
// This is needed for the Web Demo server to log the exceptions coming from the analyzer instead of showing them in the editor.
|
||||||
if (System.getProperty("kotlin.running.in.server.mode", "false").equals("true") || ApplicationManager.getApplication().isUnitTestMode()) {
|
if (System.getProperty("kotlin.running.in.server.mode", "false").equals("true") || ApplicationManager.getApplication().isUnitTestMode()) {
|
||||||
|
|||||||
@@ -116,35 +116,4 @@ public class PsiDiagnosticUtils {
|
|||||||
return "(" + line + "," + column + ")";
|
return "(" + line + "," + column + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class LineAndColumnRange {
|
|
||||||
|
|
||||||
public static final LineAndColumnRange NONE = new LineAndColumnRange(LineAndColumn.NONE, LineAndColumn.NONE);
|
|
||||||
|
|
||||||
private final LineAndColumn start;
|
|
||||||
private final LineAndColumn end;
|
|
||||||
|
|
||||||
public LineAndColumnRange(LineAndColumn start, LineAndColumn end) {
|
|
||||||
this.start = start;
|
|
||||||
this.end = end;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LineAndColumn getStart() {
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LineAndColumn getEnd() {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: This method is used for presenting positions to the user
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
if (start.line == end.line) {
|
|
||||||
return "(" + start.line + "," + start.column + "-" + end.column + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
return start.toString() + " - " + end.toString();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-3
@@ -100,9 +100,7 @@ class ReplTest : TestCase() {
|
|||||||
),
|
),
|
||||||
sequenceOf(
|
sequenceOf(
|
||||||
makeFailureResult(
|
makeFailureResult(
|
||||||
"Unresolved reference: ppp", location = SourceCode.Location(
|
"Unresolved reference: ppp", location = SourceCode.Location(SourceCode.Position(3, 11))
|
||||||
SourceCode.Position(3, 11), SourceCode.Position(3, 14)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
-10
@@ -37,20 +37,10 @@ class ScriptDiagnosticsMessageCollector(private val parentMessageCollector: Mess
|
|||||||
if (mappedSeverity != null) {
|
if (mappedSeverity != null) {
|
||||||
val mappedLocation = location?.let {
|
val mappedLocation = location?.let {
|
||||||
if (it.line < 0 && it.column < 0) null // special location created by CompilerMessageLocation.create
|
if (it.line < 0 && it.column < 0) null // special location created by CompilerMessageLocation.create
|
||||||
else if (it.lineEnd < 0 && it.columnEnd < 0) SourceCode.Location(
|
|
||||||
SourceCode.Position(
|
|
||||||
it.line,
|
|
||||||
it.column
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else SourceCode.Location(
|
else SourceCode.Location(
|
||||||
SourceCode.Position(
|
SourceCode.Position(
|
||||||
it.line,
|
it.line,
|
||||||
it.column
|
it.column
|
||||||
),
|
|
||||||
SourceCode.Position(
|
|
||||||
it.lineEnd,
|
|
||||||
it.columnEnd
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
-8
@@ -86,8 +86,6 @@ class JvmIdeServicesTest : TestCase() {
|
|||||||
} else {
|
} else {
|
||||||
assertEquals(3, loc.line)
|
assertEquals(3, loc.line)
|
||||||
assertEquals(11, loc.column)
|
assertEquals(11, loc.column)
|
||||||
assertEquals(3, loc.lineEnd)
|
|
||||||
assertEquals(14, loc.columnEnd)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fail("Result should be an error")
|
fail("Result should be an error")
|
||||||
@@ -117,8 +115,6 @@ class JvmIdeServicesTest : TestCase() {
|
|||||||
} else {
|
} else {
|
||||||
assertEquals(3, loc.line)
|
assertEquals(3, loc.line)
|
||||||
assertEquals(13, loc.column)
|
assertEquals(13, loc.column)
|
||||||
assertEquals(3, loc.lineEnd)
|
|
||||||
assertEquals(16, loc.columnEnd)
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fail("Result should be an error")
|
fail("Result should be an error")
|
||||||
@@ -398,8 +394,6 @@ private fun <T> ResultWithDiagnostics<T>.getErrors(): CompilationErrors =
|
|||||||
report.sourcePath,
|
report.sourcePath,
|
||||||
loc.start.line,
|
loc.start.line,
|
||||||
loc.start.col,
|
loc.start.col,
|
||||||
loc.end?.line,
|
|
||||||
loc.end?.col,
|
|
||||||
null
|
null
|
||||||
)?.toString()?.let {
|
)?.toString()?.let {
|
||||||
"$it "
|
"$it "
|
||||||
@@ -418,8 +412,6 @@ private fun <T> ResultWithDiagnostics<T>.getErrors(): CompilationErrors =
|
|||||||
it.sourcePath,
|
it.sourcePath,
|
||||||
loc.start.line,
|
loc.start.line,
|
||||||
loc.start.col,
|
loc.start.col,
|
||||||
loc.end?.line,
|
|
||||||
loc.end?.col,
|
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-7
@@ -186,10 +186,10 @@ class ReplCompletionAndErrorsAnalysisTest : TestCase() {
|
|||||||
val c = foob
|
val c = foob
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
expect {
|
expect {
|
||||||
addError(1, 16, 1, 20, "Type mismatch: inferred type is String but Int was expected", "ERROR")
|
addError(1, 16, "Type mismatch: inferred type is String but Int was expected", "ERROR")
|
||||||
addError(1, 22, 1, 26, "The floating-point literal does not conform to the expected type String", "ERROR")
|
addError(1, 22, "The floating-point literal does not conform to the expected type String", "ERROR")
|
||||||
addError(2, 14, 2, 19, "Type mismatch: inferred type is String but Int was expected", "ERROR")
|
addError(2, 14, "Type mismatch: inferred type is String but Int was expected", "ERROR")
|
||||||
addError(3, 9, 3, 13, "Unresolved reference: foob", "ERROR")
|
addError(3, 9, "Unresolved reference: foob", "ERROR")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -280,15 +280,14 @@ class ReplCompletionAndErrorsAnalysisTest : TestCase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val errors = ExpectedList<ScriptDiagnostic>(run::doErrorCheck)
|
val errors = ExpectedList<ScriptDiagnostic>(run::doErrorCheck)
|
||||||
fun addError(startLine: Int, startCol: Int, endLine: Int, endCol: Int, message: String, severity: String) {
|
fun addError(startLine: Int, startCol: Int, message: String, severity: String) {
|
||||||
errors.add(
|
errors.add(
|
||||||
ScriptDiagnostic(
|
ScriptDiagnostic(
|
||||||
ScriptDiagnostic.unspecifiedError,
|
ScriptDiagnostic.unspecifiedError,
|
||||||
message,
|
message,
|
||||||
ScriptDiagnostic.Severity.valueOf(severity),
|
ScriptDiagnostic.Severity.valueOf(severity),
|
||||||
location = SourceCode.Location(
|
location = SourceCode.Location(
|
||||||
SourceCode.Position(startLine, startCol),
|
SourceCode.Position(startLine, startCol)
|
||||||
SourceCode.Position(endLine, endCol)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user