Do not queue bg task under read action
Relates to #EA-218701
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
6e7b5a55b3
commit
b6f958f856
+32
-31
@@ -16,7 +16,6 @@ import com.intellij.openapi.project.DumbService
|
|||||||
import com.intellij.openapi.project.Project
|
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
|
||||||
@@ -56,41 +55,43 @@ class KtScratchExecutionSession(
|
|||||||
if (!executor.checkForErrors(psiFile, expressions)) return
|
if (!executor.checkForErrors(psiFile, expressions)) return
|
||||||
|
|
||||||
val project = file.project
|
val project = file.project
|
||||||
ReadAction.nonBlocking {
|
when (val result = runReadAction { KtScratchSourceFileProcessor().process(expressions) }) {
|
||||||
when (val result = KtScratchSourceFileProcessor().process(expressions)) {
|
is KtScratchSourceFileProcessor.Result.Error -> return executor.errorOccurs(result.message, isFatal = true)
|
||||||
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}")
|
|
||||||
|
|
||||||
object : Task.Backgroundable(psiFile.project, KotlinJvmBundle.message("running.kotlin.scratch"), true) {
|
object : Task.Backgroundable(psiFile.project, KotlinJvmBundle.message("running.kotlin.scratch"), true) {
|
||||||
override fun run(indicator: ProgressIndicator) {
|
override fun run(indicator: ProgressIndicator) {
|
||||||
backgroundProcessIndicator = indicator
|
backgroundProcessIndicator = indicator
|
||||||
|
|
||||||
val modifiedScratchSourceFile = runReadAction {
|
ReadAction.nonBlocking {
|
||||||
KtPsiFactory(psiFile.project).createFileWithLightClassSupport("tmp.kt", result.code, psiFile)
|
val modifiedScratchSourceFile = runReadAction {
|
||||||
}
|
KtPsiFactory(psiFile.project).createFileWithLightClassSupport("tmp.kt", result.code, psiFile)
|
||||||
|
|
||||||
try {
|
|
||||||
runCommandLine(project, modifiedScratchSourceFile, expressions, psiFile, result, indicator, callback)
|
|
||||||
} catch (e: Throwable) {
|
|
||||||
if (e is ControlFlowException) throw e
|
|
||||||
|
|
||||||
LOG.printDebugMessage(result.code)
|
|
||||||
executor.errorOccurs(
|
|
||||||
e.message ?: KotlinJvmBundle.message("couldn.t.compile.0", psiFile.name),
|
|
||||||
e,
|
|
||||||
isFatal = true
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.queue()
|
|
||||||
|
try {
|
||||||
|
runCommandLine(project, modifiedScratchSourceFile, expressions, psiFile, result, indicator, callback)
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
if (e is ControlFlowException) throw e
|
||||||
|
|
||||||
|
LOG.printDebugMessage(result.code)
|
||||||
|
executor.errorOccurs(
|
||||||
|
e.message ?: KotlinJvmBundle.message("couldn.t.compile.0", psiFile.name),
|
||||||
|
e,
|
||||||
|
isFatal = true
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.inSmartMode(project)
|
||||||
|
.wrapProgress(indicator)
|
||||||
|
.withDocumentsCommitted(project)
|
||||||
|
.executeSynchronously()
|
||||||
}
|
}
|
||||||
}
|
}.queue()
|
||||||
}
|
}
|
||||||
.inSmartMode(project)
|
}
|
||||||
.expireWith(project)
|
|
||||||
.withDocumentsCommitted(project)
|
|
||||||
.submit(NonUrgentExecutor.getInstance())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun runCommandLine(
|
private fun runCommandLine(
|
||||||
|
|||||||
Reference in New Issue
Block a user