[REPL] Fix syntax errors analysis and incompleteness detection
This commit is contained in:
+6
-10
@@ -92,7 +92,7 @@ open class KJvmReplCompilerBase<AnalyzerT : ReplCodeAnalyzerBase> protected cons
|
||||
snippet,
|
||||
messageCollector,
|
||||
compilationState,
|
||||
checkSyntaxErrors = true
|
||||
failOnSyntaxErrors = true
|
||||
).valueOr { return@withMessageCollector it }
|
||||
|
||||
val (sourceFiles, sourceDependencies) = collectRefinedSourcesAndUpdateEnvironment(
|
||||
@@ -242,7 +242,7 @@ open class KJvmReplCompilerBase<AnalyzerT : ReplCodeAnalyzerBase> protected cons
|
||||
snippet: SourceCode,
|
||||
parentMessageCollector: MessageCollector,
|
||||
compilationState: JvmReplCompilerState.Compilation,
|
||||
checkSyntaxErrors: Boolean
|
||||
failOnSyntaxErrors: Boolean
|
||||
): ResultWithDiagnostics<AnalyzePreparationResult> =
|
||||
withMessageCollector(
|
||||
snippet,
|
||||
@@ -269,15 +269,11 @@ open class KJvmReplCompilerBase<AnalyzerT : ReplCodeAnalyzerBase> protected cons
|
||||
)
|
||||
.valueOr { return it }
|
||||
|
||||
if (checkSyntaxErrors) {
|
||||
val syntaxErrorReport = AnalyzerWithCompilerReport.reportSyntaxErrors(snippetKtFile, errorHolder)
|
||||
if (syntaxErrorReport.isHasErrors && syntaxErrorReport.isAllErrorsAtEof) return failure(
|
||||
messageCollector, ScriptDiagnostic(ScriptDiagnostic.incompleteCode, "Incomplete code")
|
||||
)
|
||||
if (syntaxErrorReport.isHasErrors) return failure(
|
||||
messageCollector
|
||||
)
|
||||
val syntaxErrorReport = AnalyzerWithCompilerReport.reportSyntaxErrors(snippetKtFile, errorHolder)
|
||||
if (syntaxErrorReport.isHasErrors && syntaxErrorReport.isAllErrorsAtEof) {
|
||||
messageCollector.report(ScriptDiagnostic(ScriptDiagnostic.incompleteCode, "Incomplete code"))
|
||||
}
|
||||
if (failOnSyntaxErrors && syntaxErrorReport.isHasErrors) return failure(messageCollector)
|
||||
|
||||
return AnalyzePreparationResult(
|
||||
context,
|
||||
|
||||
+23
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.scripting.compiler.plugin.impl
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.arguments.Argument
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
@@ -58,6 +59,28 @@ class ScriptDiagnosticsMessageCollector(private val parentMessageCollector: Mess
|
||||
}
|
||||
parentMessageCollector?.report(severity, message, location)
|
||||
}
|
||||
|
||||
fun report(diagnostic: ScriptDiagnostic) {
|
||||
_diagnostics.add(diagnostic)
|
||||
|
||||
if (parentMessageCollector == null) return
|
||||
if (parentMessageCollector is ScriptDiagnosticsMessageCollector) {
|
||||
parentMessageCollector.report(diagnostic)
|
||||
return
|
||||
}
|
||||
|
||||
val locationStart = diagnostic.location?.start
|
||||
parentMessageCollector.report(
|
||||
diagnostic.severity.toCompilerMessageSeverity(),
|
||||
diagnostic.message,
|
||||
CompilerMessageLocation.create(
|
||||
null,
|
||||
locationStart?.line ?: -1,
|
||||
locationStart?.col ?: -1,
|
||||
null
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun CompilerMessageSeverity.toScriptingSeverity(): ScriptDiagnostic.Severity? = when (this) {
|
||||
|
||||
Reference in New Issue
Block a user