diff --git a/org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/console/DSPProcess.java b/org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/console/DSPProcess.java index ed59e6b71..17185734f 100644 --- a/org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/console/DSPProcess.java +++ b/org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/console/DSPProcess.java @@ -9,9 +9,13 @@ package org.eclipse.lsp4e.debug.console; import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.TimeUnit; import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.DebugEvent; import org.eclipse.debug.core.DebugException; +import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.model.IProcess; import org.eclipse.lsp4e.debug.debugmodel.DSPDebugTarget; @@ -27,6 +31,7 @@ public class DSPProcess implements IProcess { private final DSPStreamsProxy proxy; private final ProcessEventArguments processArgs; private final Optional handle; + private boolean terminated; public DSPProcess(DSPDebugTarget target) { this(target, null); @@ -50,16 +55,22 @@ public T getAdapter(Class adapter) { @Override public boolean canTerminate() { - return target.canTerminate(); + return !isTerminated(); } @Override public boolean isTerminated() { - return target.isTerminated(); + return handle.map(h -> !h.isAlive()).orElse(terminated); } @Override public void terminate() throws DebugException { + terminated = true; + handle.ifPresent(h -> { + h.destroy(); // normal termination + CompletableFuture.runAsync(() -> h.destroyForcibly(), CompletableFuture.delayedExecutor(5, TimeUnit.SECONDS)); // forced termination if normal is not sufficient + }); + DebugPlugin.getDefault().fireDebugEventSet(new DebugEvent[] { new DebugEvent(this, DebugEvent.TERMINATE) }); target.terminate(); } diff --git a/org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/debugmodel/DSPDebugTarget.java b/org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/debugmodel/DSPDebugTarget.java index 42dd3d330..4e2a8863c 100644 --- a/org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/debugmodel/DSPDebugTarget.java +++ b/org.eclipse.lsp4e.debug/src/org/eclipse/lsp4e/debug/debugmodel/DSPDebugTarget.java @@ -310,16 +310,17 @@ private void terminated() { try { t.terminate(); } catch (DebugException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + DSPPlugin.logError(e); } }); - fireTerminateEvent(); - if (process != null) { - // Disable the terminate button of the console associated with the DSPProcess. - DebugPlugin.getDefault() - .fireDebugEventSet(new DebugEvent[] { new DebugEvent(process, DebugEvent.TERMINATE) }); + if (process != null && process.canTerminate()) { + try { + process.terminate(); + } catch (DebugException e) { + DSPPlugin.logError(e); + } } + fireTerminateEvent(); if (breakpointManager != null) { breakpointManager.shutdown(); }