Commit 664e7ec4 authored by Martin Entlicher's avatar Martin Entlicher
Browse files

Assure that the TerminatedEvent is sent only after the debuggee finishes.

parent 9b5068b1
......@@ -27,7 +27,6 @@ import java.util.function.BiConsumer;
import java.util.function.Supplier;
import org.eclipse.lsp4j.debug.StoppedEventArguments;
import org.eclipse.lsp4j.debug.TerminatedEventArguments;
import org.eclipse.lsp4j.debug.ThreadEventArguments;
import org.netbeans.api.debugger.DebuggerEngine;
import org.netbeans.api.debugger.DebuggerManager;
......@@ -63,15 +62,6 @@ public final class NbThreads {
}
private void initThreads(DebugAdapterContext context, JPDADebugger debugger) {
debugger.addPropertyChangeListener(JPDADebugger.PROP_STATE, evt -> {
int newState = (int) evt.getNewValue();
switch (newState) {
case JPDADebugger.STATE_DISCONNECTED:
//debugger.removePropertyChangeListener(this);
context.getClient().terminated(new TerminatedEventArguments());
break;
}
});
DebuggerEngine engine = debugger.getSession().getCurrentEngine();
if (engine == null) {
debugger.getSession().addPropertyChangeListener(Session.PROP_CURRENT_LANGUAGE, new PropertyChangeListener() {
......
......@@ -58,8 +58,9 @@ public final class NbLaunchRequestHandler {
public CompletableFuture<Void> launch(Map<String, Object> launchArguments, DebugAdapterContext context) {
CompletableFuture<Void> resultFuture = new CompletableFuture<>();
boolean noDebug = (Boolean) launchArguments.getOrDefault("noDebug", Boolean.FALSE);
activeLaunchHandler = noDebug ? new NbLaunchWithoutDebuggingDelegate((daContext) -> handleTerminatedEvent(daContext))
: new NbLaunchWithDebuggingDelegate();
Consumer<DebugAdapterContext> terminateHandle = (daContext) -> handleTerminatedEvent(daContext);
activeLaunchHandler = noDebug ? new NbLaunchWithoutDebuggingDelegate(terminateHandle)
: new NbLaunchWithDebuggingDelegate(terminateHandle);
// validation
List<String> modulePaths = (List<String>) launchArguments.getOrDefault("modulePaths", Collections.emptyList());
List<String> classPaths = (List<String>) launchArguments.getOrDefault("classPaths", Collections.emptyList());
......
......@@ -19,6 +19,7 @@
package org.netbeans.modules.java.lsp.server.debugging.launch;
import java.util.Map;
import java.util.function.Consumer;
import org.netbeans.modules.java.lsp.server.debugging.DebugAdapterContext;
......@@ -28,6 +29,18 @@ import org.netbeans.modules.java.lsp.server.debugging.DebugAdapterContext;
*/
public final class NbLaunchWithDebuggingDelegate extends NbLaunchDelegate {
private final Consumer<DebugAdapterContext> onFinishCallback;
NbLaunchWithDebuggingDelegate(Consumer<DebugAdapterContext> onFinishCallback) {
this.onFinishCallback = onFinishCallback;
}
@Override
protected void notifyFinished(DebugAdapterContext ctx, boolean success) {
super.notifyFinished(ctx, success);
onFinishCallback.accept(ctx);
}
@Override
public void postLaunch(Map<String, Object> launchArguments, DebugAdapterContext context) {
context.getClient().initialized();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment