mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 13:02:30 +07:00
Make StopDebugProcessCommand wait until the debug process has stopped
GitOrigin-RevId: 5a88236487fc06ff25815ad710c0ec7024b3455d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
0cc0f459dc
commit
8d908b7cb3
@@ -1,36 +1,38 @@
|
||||
package com.jetbrains.performancePlugin.commands
|
||||
|
||||
import com.intellij.execution.impl.ExecutionManagerImpl
|
||||
import com.intellij.execution.ui.RunContentDescriptor
|
||||
import com.intellij.execution.ui.RunContentManager
|
||||
import com.intellij.openapi.application.WriteAction
|
||||
import com.intellij.openapi.application.writeAction
|
||||
import com.intellij.openapi.ui.playback.PlaybackContext
|
||||
import com.intellij.openapi.util.ActionCallback
|
||||
import com.intellij.openapi.ui.playback.commands.PlaybackCommandCoroutineAdapter
|
||||
import com.intellij.xdebugger.XDebuggerManager
|
||||
import com.jetbrains.performancePlugin.utils.AbstractCallbackBasedCommand
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import java.io.IOException
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
|
||||
class StopDebugProcessCommand(text: String, line: Int) : AbstractCallbackBasedCommand(text, line, true) {
|
||||
|
||||
override fun execute(callback: ActionCallback, context: PlaybackContext) {
|
||||
val debugSessions = XDebuggerManager.getInstance(context.project).debugSessions
|
||||
if (debugSessions.isEmpty()) {
|
||||
callback.reject("Debug process was not started")
|
||||
return
|
||||
}
|
||||
if (debugSessions.size > 1) {
|
||||
callback.reject("Currently running ${debugSessions.size} debug processes")
|
||||
return
|
||||
}
|
||||
|
||||
WriteAction.runAndWait<IOException> {
|
||||
val selectedContent = RunContentManager.getInstance(context.project).getSelectedContent()
|
||||
ExecutionManagerImpl.stopProcess(selectedContent)
|
||||
callback.setDone()
|
||||
}
|
||||
}
|
||||
class StopDebugProcessCommand(text: String, line: Int) : PlaybackCommandCoroutineAdapter(text, line) {
|
||||
|
||||
companion object {
|
||||
const val PREFIX: @NonNls String = CMD_PREFIX + "stopDebugProcess"
|
||||
}
|
||||
|
||||
override suspend fun doExecute(context: PlaybackContext) {
|
||||
val debugSessions = XDebuggerManager.getInstance(context.project).debugSessions
|
||||
if (debugSessions.isEmpty()) throw IllegalStateException("Debug process was not started")
|
||||
if (debugSessions.size > 1) throw IllegalStateException("Currently running ${debugSessions.size} debug processes")
|
||||
|
||||
var selectedContent: RunContentDescriptor? = null
|
||||
writeAction {
|
||||
selectedContent = RunContentManager.getInstance(context.project).getSelectedContent()
|
||||
ExecutionManagerImpl.stopProcess(selectedContent)
|
||||
}
|
||||
withTimeout(1.minutes) {
|
||||
while (selectedContent == null || selectedContent?.processHandler?.isProcessTerminated == false) {
|
||||
delay(500.milliseconds)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user