Skip to content

Commit 72099dd

Browse files
committed
Merge pull request #210 from rkeithhill/rkeithhill/is194-ctrl-f5-run
Rkeithhill/is194 ctrl f5 run
2 parents 29bbac3 + 9d0b2f2 commit 72099dd

File tree

4 files changed

+33
-13
lines changed

4 files changed

+33
-13
lines changed

src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ public class LaunchRequestArguments
2222
/// </summary>
2323
public string Program { get; set; }
2424

25+
/// <summary>
26+
/// Gets or sets a boolean value that indicates whether the script should be
27+
/// run with (false) or without (true) debugging support.
28+
/// </summary>
29+
public bool NoDebug { get; set; }
30+
2531
/// <summary>
2632
/// Gets or sets a boolean value that determines whether to automatically stop
2733
/// target after launch. If not specified, target does not stop.

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class DebugAdapter : DebugAdapterBase
2323
private OutputDebouncer outputDebouncer;
2424
private bool isConfigurationDoneRequestComplete;
2525
private bool isLaunchRequestComplete;
26+
private bool noDebug;
2627
private string scriptPathToLaunch;
2728
private string arguments;
2829

@@ -158,6 +159,7 @@ protected async Task HandleLaunchRequest(
158159
// If the launch request comes first, then stash the launch
159160
// params so that the subsequent configurationDone request handler
160161
// can launch the script.
162+
this.noDebug = launchParams.NoDebug;
161163
this.scriptPathToLaunch = launchParams.Program;
162164
this.arguments = arguments;
163165

@@ -225,9 +227,11 @@ protected async Task HandleSetBreakpointsRequest(
225227
LogLevel.Warning,
226228
$"Attempted to set breakpoints on a non-existing file: {setBreakpointsParams.Source.Path}");
227229

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

232236
// Return non-verified breakpoint message.
233237
await requestContext.SendResult(
@@ -249,16 +253,20 @@ await requestContext.SendResult(
249253
srcBreakpoint.Condition);
250254
}
251255

252-
BreakpointDetails[] breakpoints =
253-
await editorSession.DebugService.SetLineBreakpoints(
254-
scriptFile,
255-
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+
}
256265

257266
await requestContext.SendResult(
258-
new SetBreakpointsResponseBody
259-
{
267+
new SetBreakpointsResponseBody {
260268
Breakpoints =
261-
breakpoints
269+
updatedBreakpointDetails
262270
.Select(Protocol.DebugAdapter.Breakpoint.Create)
263271
.ToArray()
264272
});
@@ -277,14 +285,19 @@ protected async Task HandleSetFunctionBreakpointsRequest(
277285
funcBreakpoint.Condition);
278286
}
279287

280-
CommandBreakpointDetails[] breakpoints =
281-
await editorSession.DebugService.SetCommandBreakpoints(
282-
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+
}
283296

284297
await requestContext.SendResult(
285298
new SetBreakpointsResponseBody {
286299
Breakpoints =
287-
breakpoints
300+
updatedBreakpointDetails
288301
.Select(Protocol.DebugAdapter.Breakpoint.Create)
289302
.ToArray()
290303
});

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpoints(
8686
foreach (BreakpointDetails breakpoint in breakpoints)
8787
{
8888
PSCommand psCommand = new PSCommand();
89-
psCommand.AddCommand("Set-PSBreakpoint");
89+
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Set-PSBreakpoint");
9090
psCommand.AddParameter("Script", escapedScriptPath);
9191
psCommand.AddParameter("Line", breakpoint.LineNumber);
9292

0 commit comments

Comments
 (0)