Add FATAL severity to script dependencies resolve result
This commit is contained in:
+4
-1
@@ -22,6 +22,7 @@ import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.script.ScriptContentLoader
|
||||
import org.jetbrains.kotlin.script.ScriptDefinitionProvider
|
||||
import org.jetbrains.kotlin.script.ScriptDependenciesProvider
|
||||
import org.jetbrains.kotlin.script.adjustByDefinition
|
||||
import java.io.File
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock
|
||||
import kotlin.concurrent.read
|
||||
@@ -48,7 +49,9 @@ class CliScriptDependenciesProvider(
|
||||
else {
|
||||
val scriptDef = scriptDefinitionProvider.findScriptDefinition(file)
|
||||
if (scriptDef != null) {
|
||||
val deps = scriptContentLoader.loadContentsAndResolveDependencies(scriptDef, file)
|
||||
val deps = scriptContentLoader
|
||||
.loadContentsAndResolveDependencies(scriptDef, file)
|
||||
.dependencies?.adjustByDefinition(scriptDef)
|
||||
|
||||
if (deps != null) {
|
||||
log.info("[kts] new cached deps for $path: ${deps.classpath.joinToString(File.pathSeparator)}")
|
||||
|
||||
@@ -37,6 +37,7 @@ class CliScriptReportSink(private val messageCollector: MessageCollector) : Scri
|
||||
}
|
||||
|
||||
private fun ScriptReport.Severity.convertSeverity(): CompilerMessageSeverity = when(this) {
|
||||
ScriptReport.Severity.FATAL -> CompilerMessageSeverity.ERROR
|
||||
ScriptReport.Severity.ERROR -> CompilerMessageSeverity.ERROR
|
||||
ScriptReport.Severity.WARNING -> CompilerMessageSeverity.WARNING
|
||||
ScriptReport.Severity.INFO -> CompilerMessageSeverity.INFO
|
||||
|
||||
@@ -25,8 +25,9 @@ import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import java.io.File
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.script.experimental.dependencies.DependenciesResolver.ResolveResult.Failure
|
||||
import kotlin.script.dependencies.ScriptContents
|
||||
import kotlin.script.experimental.dependencies.DependenciesResolver
|
||||
import kotlin.script.experimental.dependencies.DependenciesResolver.ResolveResult.Failure
|
||||
import kotlin.script.experimental.dependencies.ScriptDependencies
|
||||
import kotlin.script.experimental.dependencies.ScriptReport
|
||||
|
||||
@@ -62,7 +63,7 @@ class ScriptContentLoader(private val project: Project) {
|
||||
fun loadContentsAndResolveDependencies(
|
||||
scriptDef: KotlinScriptDefinition,
|
||||
file: VirtualFile
|
||||
): ScriptDependencies? {
|
||||
): DependenciesResolver.ResolveResult {
|
||||
val scriptContents = getScriptContents(scriptDef, file)
|
||||
val environment = getEnvironment(scriptDef)
|
||||
val result = try {
|
||||
@@ -75,7 +76,7 @@ class ScriptContentLoader(private val project: Project) {
|
||||
e.asResolveFailure(scriptDef)
|
||||
}
|
||||
ServiceManager.getService(project, ScriptReportSink::class.java)?.attachReports(file, result.reports)
|
||||
return result.dependencies?.adjustByDefinition(scriptDef)
|
||||
return result
|
||||
}
|
||||
|
||||
fun getEnvironment(scriptDef: KotlinScriptDefinition) =
|
||||
@@ -92,5 +93,5 @@ fun ScriptDependencies.adjustByDefinition(
|
||||
|
||||
fun Throwable.asResolveFailure(scriptDef: KotlinScriptDefinition): Failure {
|
||||
val prefix = "${scriptDef.dependencyResolver::class.simpleName} threw exception ${this::class.simpleName}:\n "
|
||||
return Failure(ScriptReport(prefix + (message ?: "<no message>")))
|
||||
return Failure(ScriptReport(prefix + (message ?: "<no message>"), ScriptReport.Severity.FATAL))
|
||||
}
|
||||
@@ -49,7 +49,7 @@ interface DependenciesResolver : ScriptDependenciesResolver {
|
||||
|
||||
data class ScriptReport(val message: String, val severity: Severity = Severity.ERROR, val position: Position? = null) {
|
||||
data class Position(val startLine: Int, val startColumn: Int, val endLine: Int? = null, val endColumn: Int? = null)
|
||||
enum class Severity { ERROR, WARNING, INFO, DEBUG }
|
||||
enum class Severity { FATAL, ERROR, WARNING, INFO, DEBUG }
|
||||
}
|
||||
|
||||
fun ScriptDependencies.asSuccess(): ResolveResult.Success = ResolveResult.Success(this)
|
||||
+5
-1
@@ -49,6 +49,7 @@ import java.util.concurrent.Executors
|
||||
import kotlin.script.experimental.dependencies.AsyncDependenciesResolver
|
||||
import kotlin.script.experimental.dependencies.DependenciesResolver
|
||||
import kotlin.script.experimental.dependencies.ScriptDependencies
|
||||
import kotlin.script.experimental.dependencies.ScriptReport
|
||||
|
||||
class ScriptDependenciesUpdater(
|
||||
private val project: Project,
|
||||
@@ -215,7 +216,10 @@ class ScriptDependenciesUpdater(
|
||||
|
||||
|
||||
fun updateSync(file: VirtualFile, scriptDef: KotlinScriptDefinition): Boolean {
|
||||
val newDeps = contentLoader.loadContentsAndResolveDependencies(scriptDef, file) ?: return false
|
||||
val result = contentLoader.loadContentsAndResolveDependencies(scriptDef, file)
|
||||
if (result.reports.any { it.severity == ScriptReport.Severity.FATAL }) return false
|
||||
|
||||
val newDeps = result.dependencies?.adjustByDefinition(scriptDef) ?: ScriptDependencies.Empty
|
||||
return saveNewDependencies(newDeps, file)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user