@@ -41,6 +41,7 @@ import org.eclipse.lsp4j.debug.services.IDebugProtocolServer
41
41
import org.eclipse.lsp4j.jsonrpc.Launcher
42
42
import org.jetbrains.concurrency.Promise
43
43
import java.nio.file.Path
44
+ import java.util.concurrent.atomic.AtomicBoolean
44
45
import kotlin.io.path.Path
45
46
46
47
class PowerShellProgramDebugRunner : AsyncProgramRunner <RunnerSettings >() {
@@ -78,8 +79,26 @@ suspend fun bootstrapDebugSession(
78
79
val inOutPair = processRunner.establishDebuggerConnection()
79
80
? : throw CantRunException (MessagesBundle .message(" powershell.debugger.cantRunException" ))
80
81
val process = processRunner.getProcess() ? : error(" Cannot get the debugger process." )
81
- val handler = KillableProcessHandler (process, " PowerShellEditorService" ).apply {
82
- setShouldKillProcessSoftly(false )
82
+ val handler = object : KillableProcessHandler (process, " PowerShellEditorService" ) {
83
+ // Here, we have to emulate graceful termination (exit code zero), since PowerShellEditorServices doesn't fully
84
+ // support it (in debug mode at least).
85
+ //
86
+ // The expected flow is:
87
+ // 1. We are asked to terminate gracefully. We track the attempt and return false (as if we refuse).
88
+ // 2. We are terminated in the hard mode, but we emulate the normal termination by returning a zero exit code.
89
+ //
90
+ // In case we weren't asked for graceful termination, then it means something else has killed the process, so we
91
+ // don't need to emulate graceful termination.
92
+
93
+ val gracefulTerminationRequested = AtomicBoolean ()
94
+ override fun destroyProcessGracefully (): Boolean {
95
+ gracefulTerminationRequested.set(true )
96
+ return false // the graceful termination attempt is not successful, since it isn't supported
97
+ }
98
+
99
+ override fun notifyProcessTerminated (exitCode : Int ) {
100
+ super .notifyProcessTerminated(if (gracefulTerminationRequested.get()) 0 else exitCode)
101
+ }
83
102
}
84
103
val console = TerminalExecutionConsole (project, handler)
85
104
handler.startNotify()
0 commit comments