Skip to content

Commit bb5f44e

Browse files
Set IsDebuggingRemoteRunspace sooner for attach (#1815)
Since we're not setting `DebugContext.IsActive` sooner, we also need to set `IsDebuggingRemoteRunspace` early as well. Otherwise `DoOneRepl` sees `IsActive`, but not in a breakpoint, and stops debugging.
1 parent bff3b49 commit bb5f44e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/PowerShellEditorServices/Services/DebugAdapter/Handlers/LaunchAndAttachHandler.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,26 @@ public async Task<LaunchResponse> Handle(PsesLaunchRequestArguments request, Can
216216
}
217217

218218
public async Task<AttachResponse> Handle(PsesAttachRequestArguments request, CancellationToken cancellationToken)
219+
{
220+
// We want to set this as early as possible to avoid an early `StopDebugging` call in
221+
// DoOneRepl. There's too many places to reset this if it fails so we're wrapping the
222+
// entire method in a try here to reset it if failed.
223+
//
224+
// TODO: Ideally DoOneRepl would be paused until the attach is fully initialized, though
225+
// the current architecture makes that challenging.
226+
_debugService.IsDebuggingRemoteRunspace = true;
227+
try
228+
{
229+
return await HandleImpl(request, cancellationToken).ConfigureAwait(false);
230+
}
231+
catch
232+
{
233+
_debugService.IsDebuggingRemoteRunspace = false;
234+
throw;
235+
}
236+
}
237+
238+
private async Task<AttachResponse> HandleImpl(PsesAttachRequestArguments request, CancellationToken cancellationToken)
219239
{
220240
// The debugger has officially started. We use this to later check if we should stop it.
221241
((PsesInternalHost)_executionService).DebugContext.IsActive = true;
@@ -413,7 +433,6 @@ await _executionService.ExecutePSCommandAsync(
413433
// Clear any existing breakpoints before proceeding
414434
await _breakpointService.RemoveAllBreakpointsAsync().ConfigureAwait(continueOnCapturedContext: false);
415435

416-
_debugService.IsDebuggingRemoteRunspace = true;
417436
_debugStateService.WaitingForAttach = true;
418437
Task nonAwaitedTask = _executionService
419438
.ExecutePSCommandAsync(debugRunspaceCmd, CancellationToken.None, PowerShellExecutionOptions.ImmediateInteractive)

0 commit comments

Comments
 (0)