Skip to content

Commit 6390ce7

Browse files
committed
Support debugger commands in the Integrated Console.
This change enables debugger commands in the integrated console by acting on the DebuggerResumeAction that is returned by the debugger when a command gets executed. If a DebuggerResumeAction is returned, it is used to resume the debugger in whatever way the user requested by typing a command. Resolves PowerShell/vscode-powershell#600.
1 parent 8db0828 commit 6390ce7

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

+13
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public DebugAdapter(EditorSession editorSession, ChannelBase serverChannel)
4646
this.editorSession = editorSession;
4747
this.editorSession.PowerShellContext.RunspaceChanged += this.powerShellContext_RunspaceChanged;
4848
this.editorSession.DebugService.DebuggerStopped += this.DebugService_DebuggerStopped;
49+
this.editorSession.PowerShellContext.DebuggerResumed += this.powerShellContext_DebuggerResumed;
4950
}
5051

5152
public DebugAdapter(
@@ -60,6 +61,7 @@ public DebugAdapter(
6061
this.editorSession.StartDebugSession(hostDetails, profilePaths, editorOperations);
6162
this.editorSession.PowerShellContext.RunspaceChanged += this.powerShellContext_RunspaceChanged;
6263
this.editorSession.DebugService.DebuggerStopped += this.DebugService_DebuggerStopped;
64+
this.editorSession.PowerShellContext.DebuggerResumed += this.powerShellContext_DebuggerResumed;
6365

6466
// The assumption in this overload is that the debugger
6567
// is running in UI-hosted mode, no terminal interface
@@ -891,6 +893,17 @@ await this.SendEvent<ContinuedEvent>(
891893
}
892894
}
893895

896+
private async void powerShellContext_DebuggerResumed(object sender, DebuggerResumeAction e)
897+
{
898+
await this.SendEvent(
899+
ContinuedEvent.Type,
900+
new ContinuedEvent
901+
{
902+
AllThreadsContinued = true,
903+
ThreadId = 1
904+
});
905+
}
906+
894907
#endregion
895908
}
896909
}

src/PowerShellEditorServices/Session/IVersionSpecificOperations.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ IEnumerable<TResult> ExecuteCommandInDebugger<TResult>(
1919
PowerShellContext powerShellContext,
2020
Runspace currentRunspace,
2121
PSCommand psCommand,
22-
bool sendOutputToHost);
22+
bool sendOutputToHost,
23+
out DebuggerResumeAction? debuggerResumeAction);
2324
}
2425
}
2526

src/PowerShellEditorServices/Session/PowerShell3Operations.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public IEnumerable<TResult> ExecuteCommandInDebugger<TResult>(
2828
PowerShellContext powerShellContext,
2929
Runspace currentRunspace,
3030
PSCommand psCommand,
31-
bool sendOutputToHost)
31+
bool sendOutputToHost,
32+
out DebuggerResumeAction? debuggerResumeAction)
3233
{
3334
IEnumerable<TResult> executionResult = null;
3435

@@ -63,6 +64,9 @@ public IEnumerable<TResult> ExecuteCommandInDebugger<TResult>(
6364
}
6465
}
6566

67+
// No DebuggerResumeAction result for PowerShell v3
68+
debuggerResumeAction = null;
69+
6670
return executionResult;
6771
}
6872
}

src/PowerShellEditorServices/Session/PowerShell4Operations.cs

+7-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ public IEnumerable<TResult> ExecuteCommandInDebugger<TResult>(
3333
PowerShellContext powerShellContext,
3434
Runspace currentRunspace,
3535
PSCommand psCommand,
36-
bool sendOutputToHost)
36+
bool sendOutputToHost,
37+
out DebuggerResumeAction? debuggerResumeAction)
3738
{
39+
debuggerResumeAction = null;
3840
PSDataCollection<PSObject> outputCollection = new PSDataCollection<PSObject>();
3941

4042
#if !PowerShellv3
@@ -56,6 +58,10 @@ public IEnumerable<TResult> ExecuteCommandInDebugger<TResult>(
5658
currentRunspace.Debugger.ProcessCommand(
5759
psCommand,
5860
outputCollection);
61+
62+
// Pass along the debugger's resume action if the user's
63+
// command caused one to be returned
64+
debuggerResumeAction = commandResults.ResumeAction;
5965
#endif
6066

6167
IEnumerable<TResult> results = null;

src/PowerShellEditorServices/Session/PowerShellContext.cs

+15-5
Original file line numberDiff line numberDiff line change
@@ -1089,11 +1089,21 @@ private IEnumerable<TResult> ExecuteCommandInDebugger<TResult>(PSCommand psComma
10891089
"Attempting to execute command(s) in the debugger:\r\n\r\n{0}",
10901090
GetStringForPSCommand(psCommand)));
10911091

1092-
return this.versionSpecificOperations.ExecuteCommandInDebugger<TResult>(
1093-
this,
1094-
this.CurrentRunspace.Runspace,
1095-
psCommand,
1096-
sendOutputToHost);
1092+
IEnumerable<TResult> output =
1093+
this.versionSpecificOperations.ExecuteCommandInDebugger<TResult>(
1094+
this,
1095+
this.CurrentRunspace.Runspace,
1096+
psCommand,
1097+
sendOutputToHost,
1098+
out DebuggerResumeAction? debuggerResumeAction);
1099+
1100+
if (debuggerResumeAction.HasValue)
1101+
{
1102+
// Resume the debugger with the specificed action
1103+
this.ResumeDebugger(debuggerResumeAction.Value);
1104+
}
1105+
1106+
return output;
10971107
}
10981108

10991109
internal void WriteOutput(string outputString, bool includeNewLine)

0 commit comments

Comments
 (0)