Skip to content

Commit f7263e4

Browse files
committed
Updated approach to how we handle Ctrl+F5. We assume that we receive the launchRequest *before* any setBreakpoint requests come in. We stash the value of noDebug when we get the launchRequest and then when we get the setBreakpoint request and noDebug is true, we skip the bit that actually sets the breakpoints. However we tell VSCode that the breakpoints were set so they show up like normal in the editor.
1 parent 98515ad commit f7263e4

File tree

3 files changed

+24
-34
lines changed

3 files changed

+24
-34
lines changed

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ protected override void Initialize()
7373

7474
protected Task LaunchScript(RequestContext<object> requestContext)
7575
{
76-
// If this is a run without debugging session, disable all breakpoints.
77-
if (this.noDebug)
78-
{
79-
Task disableBreakpointsTask =
80-
this.editorSession.DebugService.DisableAllBreakpoints();
81-
Task.WhenAll(disableBreakpointsTask);
82-
}
83-
8476
return editorSession.PowerShellContext
8577
.ExecuteScriptAtPath(this.scriptPathToLaunch, this.arguments)
8678
.ContinueWith(
@@ -235,9 +227,11 @@ protected async Task HandleSetBreakpointsRequest(
235227
LogLevel.Warning,
236228
$"Attempted to set breakpoints on a non-existing file: {setBreakpointsParams.Source.Path}");
237229

230+
string message = this.noDebug ? null : "Source does not exist, breakpoint not set.";
231+
238232
var srcBreakpoints = setBreakpointsParams.Breakpoints
239233
.Select(srcBkpt => Protocol.DebugAdapter.Breakpoint.Create(
240-
srcBkpt, setBreakpointsParams.Source.Path, "Source does not exist, breakpoint not set."));
234+
srcBkpt, setBreakpointsParams.Source.Path, message, verified: this.noDebug));
241235

242236
// Return non-verified breakpoint message.
243237
await requestContext.SendResult(
@@ -259,16 +253,20 @@ await requestContext.SendResult(
259253
srcBreakpoint.Condition);
260254
}
261255

262-
BreakpointDetails[] breakpoints =
263-
await editorSession.DebugService.SetLineBreakpoints(
264-
scriptFile,
265-
breakpointDetails);
256+
// If this is a "run without debugging (Ctrl+F5)" session ignore requests to set breakpoints.
257+
BreakpointDetails[] updatedBreakpointDetails = breakpointDetails;
258+
if (!this.noDebug)
259+
{
260+
updatedBreakpointDetails =
261+
await editorSession.DebugService.SetLineBreakpoints(
262+
scriptFile,
263+
breakpointDetails);
264+
}
266265

267266
await requestContext.SendResult(
268-
new SetBreakpointsResponseBody
269-
{
267+
new SetBreakpointsResponseBody {
270268
Breakpoints =
271-
breakpoints
269+
updatedBreakpointDetails
272270
.Select(Protocol.DebugAdapter.Breakpoint.Create)
273271
.ToArray()
274272
});
@@ -287,14 +285,19 @@ protected async Task HandleSetFunctionBreakpointsRequest(
287285
funcBreakpoint.Condition);
288286
}
289287

290-
CommandBreakpointDetails[] breakpoints =
291-
await editorSession.DebugService.SetCommandBreakpoints(
292-
breakpointDetails);
288+
// If this is a "run without debugging (Ctrl+F5)" session ignore requests to set breakpoints.
289+
CommandBreakpointDetails[] updatedBreakpointDetails = breakpointDetails;
290+
if (!this.noDebug)
291+
{
292+
updatedBreakpointDetails =
293+
await editorSession.DebugService.SetCommandBreakpoints(
294+
breakpointDetails);
295+
}
293296

294297
await requestContext.SendResult(
295298
new SetBreakpointsResponseBody {
296299
Breakpoints =
297-
breakpoints
300+
updatedBreakpointDetails
298301
.Select(Protocol.DebugAdapter.Breakpoint.Create)
299302
.ToArray()
300303
});

src/PowerShellEditorServices/Debugging/BreakpointDetails.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public static BreakpointDetails Create(
5353

5454
return new BreakpointDetails
5555
{
56+
Verified = true,
5657
Source = source,
5758
LineNumber = line,
5859
ColumnNumber = column,

src/PowerShellEditorServices/Debugging/DebugService.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,6 @@ public DebugService(PowerShellContext powerShellContext)
5757

5858
#region Public Methods
5959

60-
/// <summary>
61-
/// Disables all breakpoints in the runspace.
62-
/// </summary>
63-
/// <returns></returns>
64-
public async Task DisableAllBreakpoints()
65-
{
66-
var psCommand = new PSCommand();
67-
68-
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Get-PSBreakpoint");
69-
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Disable-PSBreakpoint");
70-
71-
await this.powerShellContext.ExecuteCommand(psCommand);
72-
}
73-
7460
/// <summary>
7561
/// Sets the list of line breakpoints for the current debugging session.
7662
/// </summary>

0 commit comments

Comments
 (0)