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
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.scripting.ide_services
import junit.framework.TestCase
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocationWithRange
import org.jetbrains.kotlin.scripting.ide_services.test_util.JvmTestRepl
import org.jetbrains.kotlin.scripting.ide_services.test_util.SourceCodeTestImpl
import java.io.File
@@ -86,6 +86,8 @@ class JvmIdeServicesTest : TestCase() {
} else {
assertEquals(3, loc.line)
assertEquals(11, loc.column)
assertEquals(3, loc.lineEnd)
assertEquals(14, loc.columnEnd)
}
} else {
fail("Result should be an error")
@@ -115,6 +117,8 @@ class JvmIdeServicesTest : TestCase() {
} else {
assertEquals(3, loc.line)
assertEquals(13, loc.column)
assertEquals(3, loc.lineEnd)
assertEquals(16, loc.columnEnd)
}
} else {
fail("Result should be an error")
@@ -383,17 +387,19 @@ private fun checkCompile(repl: JvmTestRepl, line: String): LinkedSnippet<KJvmCom
private data class CompilationErrors(
val message: String,
val location: CompilerMessageLocation?
val location: CompilerMessageLocationWithRange?
)
private fun <T> ResultWithDiagnostics<T>.getErrors(): CompilationErrors =
CompilationErrors(
reports.joinToString("\n") { report ->
report.location?.let { loc ->
CompilerMessageLocation.create(
CompilerMessageLocationWithRange.create(
report.sourcePath,
loc.start.line,
loc.start.col,
loc.end?.line,
loc.end?.col,
null
)?.toString()?.let {
"$it "
@@ -408,10 +414,12 @@ private fun <T> ResultWithDiagnostics<T>.getErrors(): CompilationErrors =
}
}?.let {
val loc = it.location ?: return@let null
CompilerMessageLocation.create(
CompilerMessageLocationWithRange.create(
it.sourcePath,
loc.start.line,
loc.start.col,
loc.end?.line,
loc.end?.col,
null
)
}
@@ -189,10 +189,10 @@ class ReplCompletionAndErrorsAnalysisTest : TestCase() {
val c = foob
""".trimIndent()
expect {
addError(1, 16, "Type mismatch: inferred type is String but Int was expected", "ERROR")
addError(1, 22, "The floating-point literal does not conform to the expected type String", "ERROR")
addError(2, 14, "Type mismatch: inferred type is String but Int was expected", "ERROR")
addError(3, 9, "Unresolved reference: foob", "ERROR")
addError(1, 16, 1, 20, "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(2, 14, 2, 19, "Type mismatch: inferred type is String but Int was expected", "ERROR")
addError(3, 9, 3, 13, "Unresolved reference: foob", "ERROR")
}
}
}
@@ -341,14 +341,15 @@ class ReplCompletionAndErrorsAnalysisTest : TestCase() {
}
val errors = ExpectedList<ScriptDiagnostic>(run::doErrorCheck)
fun addError(startLine: Int, startCol: Int, message: String, severity: String) {
fun addError(startLine: Int, startCol: Int, endLine: Int, endCol: Int, message: String, severity: String) {
errors.add(
ScriptDiagnostic(
ScriptDiagnostic.unspecifiedError,
message,
ScriptDiagnostic.Severity.valueOf(severity),
location = SourceCode.Location(
SourceCode.Position(startLine, startCol)
SourceCode.Position(startLine, startCol),
SourceCode.Position(endLine, endCol)
)
)
)