Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support termination of virtual DSPProcess #834

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,6 +31,7 @@ public class DSPProcess implements IProcess {
private final DSPStreamsProxy proxy;
private final ProcessEventArguments processArgs;
private final Optional<ProcessHandle> handle;
private boolean terminated;

public DSPProcess(DSPDebugTarget target) {
this(target, null);
Expand All @@ -50,16 +55,22 @@ public <T> T getAdapter(Class<T> 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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down