diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleKeeper.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleKeeper.kt index 00eaf21ff4d..0728a7d5326 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleKeeper.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleKeeper.kt @@ -44,11 +44,11 @@ public class KotlinConsoleKeeper(val project: Project) { fun putVirtualFileToConsole(virtualFile: VirtualFile, console: KotlinConsoleRunner) = consoleMap.put(virtualFile, console) fun removeConsole(virtualFile: VirtualFile) = consoleMap.remove(virtualFile) - fun run(module: Module, testMode: Boolean = false): KotlinConsoleRunner? { + fun run(module: Module, previousCompilationFailed: Boolean = false, testMode: Boolean = false): KotlinConsoleRunner? { val path = module.moduleFilePath val cmdLine = createCommandLine(module) ?: return errorNotification(project, "Module SDK not found") let { null } - val consoleRunner = KotlinConsoleRunner(cmdLine, module, testMode, project, REPL_TITLE, path) + val consoleRunner = KotlinConsoleRunner(cmdLine, module, previousCompilationFailed, testMode, project, REPL_TITLE, path) consoleRunner.initAndRun() consoleRunner.setupGutters() diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleRunner.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleRunner.kt index 963bbd06e8a..638afeb8e57 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleRunner.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/KotlinConsoleRunner.kt @@ -48,6 +48,7 @@ import kotlin.properties.Delegates public class KotlinConsoleRunner( private val cmdLine: GeneralCommandLine, private val module: Module, + private val previousCompilationFailed: Boolean, private val testMode: Boolean, myProject: Project, title: String, @@ -105,7 +106,7 @@ public class KotlinConsoleRunner( disposableDescriptor = contentDescriptor val actionList = arrayListOf( - BuildAndRestartConsoleAction(project, module, defaultExecutor, contentDescriptor, restarter, testMode), + BuildAndRestartConsoleAction(project, module, defaultExecutor, contentDescriptor, previousCompilationFailed, testMode), createConsoleExecAction(consoleExecuteActionHandler), createCloseAction(defaultExecutor, contentDescriptor) ) @@ -116,12 +117,6 @@ public class KotlinConsoleRunner( override fun createConsoleExecAction(consoleExecuteActionHandler: ProcessBackedConsoleExecuteActionHandler) = ConsoleExecuteAction(consoleView, consoleExecuteActionHandler, "KotlinShellExecute", consoleExecuteActionHandler) - private val restarter = object : Consumer { - override fun consume(module: Module) { - KotlinConsoleKeeper.getInstance(project).run(module) - } - } - override fun constructConsoleTitle(title: String) = "$title (in module ${module.name})" private fun setupPlaceholder(editor: EditorEx) { diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/console/actions/BuildAndRestartConsoleAction.kt b/idea/idea-repl/src/org/jetbrains/kotlin/console/actions/BuildAndRestartConsoleAction.kt index d672c86661c..26160959a11 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/console/actions/BuildAndRestartConsoleAction.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/console/actions/BuildAndRestartConsoleAction.kt @@ -27,11 +27,10 @@ import com.intellij.notification.Notifications import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.compiler.CompileContext -import com.intellij.openapi.compiler.CompileStatusNotification import com.intellij.openapi.compiler.CompilerManager import com.intellij.openapi.module.Module import com.intellij.openapi.project.Project -import com.intellij.util.Consumer +import org.jetbrains.kotlin.console.KotlinConsoleKeeper import javax.swing.event.HyperlinkEvent private fun buildAndRestartMessage(module: Module) = "Build module '${module.name}' and restart" @@ -41,33 +40,36 @@ public class BuildAndRestartConsoleAction( private val module: Module, private val executor: Executor, private val contentDescriptor: RunContentDescriptor, - private val restarter: Consumer, + private val previousCompilationFailed: Boolean, private val testMode: Boolean ) : AnAction("Build and restart", buildAndRestartMessage(module), AllIcons.Actions.Restart) { init { - if (!testMode) showOutdatedClassedNotificationIfNeeded() + if (!testMode && !previousCompilationFailed) showOutdatedClassesNotificationIfNeeded() } override fun actionPerformed(_: AnActionEvent) = compileModule() private fun compileModule() { if (ExecutionManager.getInstance(project).contentManager.removeRunContent(executor, contentDescriptor)) { - CompilerManager.getInstance(project).make(module, object : CompileStatusNotification { - override fun finished(aborted: Boolean, errors: Int, warnings: Int, compileContext: CompileContext): Unit - = if (!module.isDisposed) restarter.consume(module) - }) + CompilerManager.getInstance(project).make(module) { + aborted: Boolean, errors: Int, warnings: Int, compileContext: CompileContext -> + if (!module.isDisposed) { + val compilationFailed = aborted || errors > 0 + if (compilationFailed) warningNotification("Compilation wasn't ended properly") + + KotlinConsoleKeeper.getInstance(project).run(module, previousCompilationFailed = compilationFailed) + } + } } } - private fun showOutdatedClassedNotificationIfNeeded() { + private fun showOutdatedClassesNotificationIfNeeded() { val compilerManager = CompilerManager.getInstance(project) val compilerScope = compilerManager.createModuleCompileScope(module, true) if (compilerManager.isUpToDate(compilerScope)) return - val warningTag = "KOTLIN REPL WARNING" - val warningTitle = "Kotlin REPL Configuration Warning" - + val message = "You’re running the REPL with outdated classes
${buildAndRestartMessage(module)}" val hyperlinkListener = object : NotificationListener { override fun hyperlinkUpdate(notification: Notification, event: HyperlinkEvent) { if (event.eventType == HyperlinkEvent.EventType.ACTIVATED) { @@ -77,14 +79,13 @@ public class BuildAndRestartConsoleAction( } } - Notifications.Bus.notify( - Notification( - warningTag, warningTitle, - "You’re running the REPL with outdated classes
${buildAndRestartMessage(module)}", - NotificationType.WARNING, - hyperlinkListener - ), - project - ) + warningNotification(message, hyperlinkListener) + } + + private fun warningNotification(message: String, hyperlinkListener: NotificationListener? = null) { + val warningTag = "KOTLIN REPL WARNING" + val warningTitle = "Kotlin REPL Configuration Warning" + + Notifications.Bus.notify(Notification(warningTag, warningTitle, message, NotificationType.WARNING, hyperlinkListener), project) } } \ No newline at end of file