KtScratchExecutionSession: fix INRE
#EA-218701 Fixed
This commit is contained in:
+37
-16
@@ -7,13 +7,16 @@ package org.jetbrains.kotlin.idea.scratch.compile
|
|||||||
|
|
||||||
import com.intellij.execution.configurations.GeneralCommandLine
|
import com.intellij.execution.configurations.GeneralCommandLine
|
||||||
import com.intellij.execution.process.CapturingProcessHandler
|
import com.intellij.execution.process.CapturingProcessHandler
|
||||||
|
import com.intellij.openapi.application.ReadAction
|
||||||
import com.intellij.openapi.diagnostic.ControlFlowException
|
import com.intellij.openapi.diagnostic.ControlFlowException
|
||||||
import com.intellij.openapi.module.Module
|
import com.intellij.openapi.module.Module
|
||||||
import com.intellij.openapi.progress.ProgressIndicator
|
import com.intellij.openapi.progress.ProgressIndicator
|
||||||
import com.intellij.openapi.progress.Task
|
import com.intellij.openapi.progress.Task
|
||||||
import com.intellij.openapi.project.DumbService
|
import com.intellij.openapi.project.DumbService
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
import com.intellij.openapi.util.Computable
|
import com.intellij.openapi.util.Computable
|
||||||
import com.intellij.openapi.util.io.FileUtil
|
import com.intellij.openapi.util.io.FileUtil
|
||||||
|
import com.intellij.util.concurrency.NonUrgentExecutor
|
||||||
import org.jetbrains.kotlin.codegen.ClassBuilderFactories
|
import org.jetbrains.kotlin.codegen.ClassBuilderFactories
|
||||||
import org.jetbrains.kotlin.codegen.KotlinCodegenFacade
|
import org.jetbrains.kotlin.codegen.KotlinCodegenFacade
|
||||||
import org.jetbrains.kotlin.codegen.filterClassFiles
|
import org.jetbrains.kotlin.codegen.filterClassFiles
|
||||||
@@ -39,6 +42,7 @@ class KtScratchExecutionSession(
|
|||||||
private const val TIMEOUT_MS = 30000
|
private const val TIMEOUT_MS = 30000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Volatile
|
||||||
private var backgroundProcessIndicator: ProgressIndicator? = null
|
private var backgroundProcessIndicator: ProgressIndicator? = null
|
||||||
|
|
||||||
fun execute(callback: () -> Unit) {
|
fun execute(callback: () -> Unit) {
|
||||||
@@ -47,8 +51,10 @@ class KtScratchExecutionSession(
|
|||||||
val expressions = file.getExpressions()
|
val expressions = file.getExpressions()
|
||||||
if (!executor.checkForErrors(psiFile, expressions)) return
|
if (!executor.checkForErrors(psiFile, expressions)) return
|
||||||
|
|
||||||
when (val result = runReadAction { KtScratchSourceFileProcessor().process(expressions) }) {
|
val project = file.project
|
||||||
is KtScratchSourceFileProcessor.Result.Error -> return executor.errorOccurs(result.message, isFatal = true)
|
ReadAction.nonBlocking {
|
||||||
|
when (val result = KtScratchSourceFileProcessor().process(expressions)) {
|
||||||
|
is KtScratchSourceFileProcessor.Result.Error -> return@nonBlocking executor.errorOccurs(result.message, isFatal = true)
|
||||||
is KtScratchSourceFileProcessor.Result.OK -> {
|
is KtScratchSourceFileProcessor.Result.OK -> {
|
||||||
LOG.printDebugMessage("After processing by KtScratchSourceFileProcessor:\n ${result.code}")
|
LOG.printDebugMessage("After processing by KtScratchSourceFileProcessor:\n ${result.code}")
|
||||||
|
|
||||||
@@ -61,11 +67,36 @@ class KtScratchExecutionSession(
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val tempDir = DumbService.getInstance(project).runReadActionInSmartMode(
|
runCommandLine(project, modifiedScratchSourceFile, expressions, psiFile, result, indicator, callback)
|
||||||
Computable {
|
} catch (e: Throwable) {
|
||||||
compileFileToTempDir(modifiedScratchSourceFile, expressions)
|
if (e is ControlFlowException) throw e
|
||||||
|
|
||||||
|
LOG.printDebugMessage(result.code)
|
||||||
|
executor.errorOccurs(e.message ?: "Couldn't compile ${psiFile.name}", e, isFatal = true)
|
||||||
}
|
}
|
||||||
) ?: return
|
}
|
||||||
|
}.queue()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.inSmartMode(project)
|
||||||
|
.expireWith(project)
|
||||||
|
.withDocumentsCommitted(project)
|
||||||
|
.submit(NonUrgentExecutor.getInstance())
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun runCommandLine(
|
||||||
|
project: Project,
|
||||||
|
modifiedScratchSourceFile: KtFile,
|
||||||
|
expressions: List<ScratchExpression>,
|
||||||
|
psiFile: KtFile,
|
||||||
|
result: KtScratchSourceFileProcessor.Result.OK,
|
||||||
|
indicator: ProgressIndicator,
|
||||||
|
callback: () -> Unit
|
||||||
|
) {
|
||||||
|
val tempDir = DumbService.getInstance(project).runReadActionInSmartMode(Computable {
|
||||||
|
compileFileToTempDir(modifiedScratchSourceFile, expressions)
|
||||||
|
}) ?: return
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val commandLine = createCommandLine(psiFile, file.module, result.mainClassName, tempDir.path)
|
val commandLine = createCommandLine(psiFile, file.module, result.mainClassName, tempDir.path)
|
||||||
@@ -89,16 +120,6 @@ class KtScratchExecutionSession(
|
|||||||
tempDir.delete()
|
tempDir.delete()
|
||||||
callback()
|
callback()
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
|
||||||
if (e is ControlFlowException) throw e
|
|
||||||
|
|
||||||
LOG.printDebugMessage(result.code)
|
|
||||||
executor.errorOccurs(e.message ?: "Couldn't compile ${psiFile.name}", e, isFatal = true)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}.queue()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
|||||||
Reference in New Issue
Block a user