Skip to content

Commit 3401153

Browse files
committed
Fix #194 - ctrl+f5 runs without debugging
1 parent 29bbac3 commit 3401153

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
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: 9 additions & 0 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

@@ -72,6 +73,13 @@ protected override void Initialize()
7273

7374
protected Task LaunchScript(RequestContext<object> requestContext)
7475
{
76+
// If this is a run without debugging session, disable all breakpoints.
77+
if (this.noDebug)
78+
{
79+
Task diableBreakpoints = this.editorSession.DebugService.DisableAllBreakpoints();
80+
Task.WhenAll(diableBreakpoints);
81+
}
82+
7583
return editorSession.PowerShellContext
7684
.ExecuteScriptAtPath(this.scriptPathToLaunch, this.arguments)
7785
.ContinueWith(
@@ -158,6 +166,7 @@ protected async Task HandleLaunchRequest(
158166
// If the launch request comes first, then stash the launch
159167
// params so that the subsequent configurationDone request handler
160168
// can launch the script.
169+
this.noDebug = launchParams.NoDebug;
161170
this.scriptPathToLaunch = launchParams.Program;
162171
this.arguments = arguments;
163172

src/PowerShellEditorServices/Debugging/DebugService.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,20 @@ 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+
6074
/// <summary>
6175
/// Sets the list of line breakpoints for the current debugging session.
6276
/// </summary>
@@ -86,7 +100,7 @@ public async Task<BreakpointDetails[]> SetLineBreakpoints(
86100
foreach (BreakpointDetails breakpoint in breakpoints)
87101
{
88102
PSCommand psCommand = new PSCommand();
89-
psCommand.AddCommand("Set-PSBreakpoint");
103+
psCommand.AddCommand(@"Microsoft.PowerShell.Utility\Set-PSBreakpoint");
90104
psCommand.AddParameter("Script", escapedScriptPath);
91105
psCommand.AddParameter("Line", breakpoint.LineNumber);
92106

0 commit comments

Comments
 (0)