Skip to content

Commit

Permalink
Support termination of virtual DSPProcess
Browse files Browse the repository at this point in the history
The DSPProcess not always maps to an actual process, but when it does,
we use it to control termination actions and state, and if it doesn't we
failback to an internal state.

This makes that the "Terminate" button on the Console works.
  • Loading branch information
mickaelistria committed Oct 3, 2023
1 parent 9409bcf commit 46a8a23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import java.util.Optional;

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 +29,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 +53,19 @@ 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(ProcessHandle::destroyForcibly);
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

0 comments on commit 46a8a23

Please sign in to comment.