Add diagnostic code to the ScriptDiagnostic
to allow checking for specific errors, e.g. incomplete statements in the REPL
This commit is contained in:
+4
-2
@@ -51,10 +51,12 @@ fun mapToLegacyScriptReportPosition(pos: SourceCode.Location?): ScriptReport.Pos
|
||||
pos?.let { ScriptReport.Position(pos.start.line, pos.start.col, pos.end?.line, pos.end?.col) }
|
||||
|
||||
fun Iterable<ScriptReport>.mapToDiagnostics(): List<ScriptDiagnostic> = map { (message, severity, position) ->
|
||||
ScriptDiagnostic(message, mapLegacyDiagnosticSeverity(severity), null, mapLegacyScriptPosition(position))
|
||||
ScriptDiagnostic(
|
||||
ScriptDiagnostic.unspecifiedError, message, mapLegacyDiagnosticSeverity(severity), null, mapLegacyScriptPosition(position)
|
||||
)
|
||||
}
|
||||
|
||||
fun Iterable<ScriptDiagnostic>.mapToLegacyReports(): List<ScriptReport> = map { (message, severity, _, location, exception) ->
|
||||
fun Iterable<ScriptDiagnostic>.mapToLegacyReports(): List<ScriptReport> = map { (_, message, severity, _, location, exception) ->
|
||||
val reportMessage = if (exception == null) message else "$message ($exception)"
|
||||
ScriptReport(reportMessage, mapToLegacyScriptReportSeverity(severity), mapToLegacyScriptReportPosition(location))
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ class KJvmCompiledScript<out ScriptBase : Any> internal constructor(
|
||||
} catch (e: Throwable) {
|
||||
ResultWithDiagnostics.Failure(
|
||||
ScriptDiagnostic(
|
||||
ScriptDiagnostic.unspecifiedError,
|
||||
"Unable to instantiate class ${data.scriptClassFQName}",
|
||||
sourcePath = sourceLocationId,
|
||||
exception = e
|
||||
|
||||
Reference in New Issue
Block a user