Skip to content

Commit 639aba2

Browse files
committed
Merge pull request #172 from rkeithhill/rkeithhill/is94-impl-cond-breakpoints
Fixes #94 - adds support for conditional breakpoints
2 parents f901c6a + a6b0254 commit 639aba2

File tree

8 files changed

+470
-118
lines changed

8 files changed

+470
-118
lines changed

src/PowerShellEditorServices.Protocol/DebugAdapter/Breakpoint.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,24 @@ namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter
77
{
88
public class Breakpoint
99
{
10+
/// <summary>
11+
/// Gets an boolean indicator that if true, breakpoint could be set
12+
/// (but not necessarily at the desired location).
13+
/// </summary>
1014
public bool Verified { get; set; }
1115

16+
/// <summary>
17+
/// Gets an optional message about the state of the breakpoint. This is shown to the user
18+
/// and can be used to explain why a breakpoint could not be verified.
19+
/// </summary>
20+
public string Message { get; set; }
21+
22+
public string Source { get; set; }
23+
1224
public int Line { get; set; }
1325

26+
public int? Column { get; set; }
27+
1428
private Breakpoint()
1529
{
1630
}
@@ -20,8 +34,11 @@ public static Breakpoint Create(
2034
{
2135
return new Breakpoint
2236
{
37+
Verified = breakpointDetails.Verified,
38+
Message = breakpointDetails.Message,
39+
Source = breakpointDetails.Source,
2340
Line = breakpointDetails.LineNumber,
24-
Verified = true
41+
Column = breakpointDetails.ColumnNumber
2542
};
2643
}
2744
}

src/PowerShellEditorServices.Protocol/DebugAdapter/SetBreakpointsRequest.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77

88
namespace Microsoft.PowerShell.EditorServices.Protocol.DebugAdapter
99
{
10-
// /** SetBreakpoints request; value of command field is "setBreakpoints".
11-
// Sets multiple breakpoints for a single source and clears all previous breakpoints in that source.
12-
// To clear all breakpoint for a source, specify an empty array.
13-
// When a breakpoint is hit, a StoppedEvent (event type 'breakpoint') is generated.
14-
// */
10+
/// <summary>
11+
/// SetBreakpoints request; value of command field is "setBreakpoints".
12+
/// Sets multiple breakpoints for a single source and clears all previous breakpoints in that source.
13+
/// To clear all breakpoint for a source, specify an empty array.
14+
/// When a breakpoint is hit, a StoppedEvent (event type 'breakpoint') is generated.
15+
/// </summary>
1516
public class SetBreakpointsRequest
1617
{
1718
public static readonly
@@ -23,12 +24,20 @@ public class SetBreakpointsRequestArguments
2324
{
2425
public Source Source { get; set; }
2526

26-
public int[] Lines { get; set; }
27+
public SourceBreakpoint[] Breakpoints { get; set; }
28+
}
29+
30+
public class SourceBreakpoint
31+
{
32+
public int Line { get; set; }
33+
34+
public int? Column { get; set; }
35+
36+
public string Condition { get; set; }
2737
}
2838

2939
public class SetBreakpointsResponseBody
3040
{
3141
public Breakpoint[] Breakpoints { get; set; }
3242
}
3343
}
34-

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,21 @@ protected async Task HandleSetBreakpointsRequest(
172172
editorSession.Workspace.GetFile(
173173
setBreakpointsParams.Source.Path);
174174

175+
var breakpointDetails = new BreakpointDetails[setBreakpointsParams.Breakpoints.Length];
176+
for (int i = 0; i < breakpointDetails.Length; i++)
177+
{
178+
SourceBreakpoint srcBreakpoint = setBreakpointsParams.Breakpoints[i];
179+
breakpointDetails[i] = BreakpointDetails.Create(
180+
scriptFile.FilePath,
181+
srcBreakpoint.Line,
182+
srcBreakpoint.Column,
183+
srcBreakpoint.Condition);
184+
}
185+
175186
BreakpointDetails[] breakpoints =
176-
await editorSession.DebugService.SetBreakpoints(
187+
await editorSession.DebugService.SetLineBreakpoints(
177188
scriptFile,
178-
setBreakpointsParams.Lines);
189+
breakpointDetails);
179190

180191
await requestContext.SendResult(
181192
new SetBreakpointsResponseBody

src/PowerShellEditorServices.Protocol/Server/DebugAdapterBase.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ await requestContext.SendEvent(
6060
null);
6161

6262
// Now send the Initialize response to continue setup
63-
await requestContext.SendResult(new InitializeResponseBody());
63+
await requestContext.SendResult(
64+
new InitializeResponseBody
65+
{
66+
SupportsConditionalBreakpoints = true,
67+
});
6468
}
6569
}
6670
}

src/PowerShellEditorServices/Debugging/BreakpointDetails.cs

Lines changed: 74 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6-
using Microsoft.PowerShell.EditorServices.Utility;
76
using System;
87
using System.Management.Automation;
8+
using Microsoft.PowerShell.EditorServices.Utility;
99

1010
namespace Microsoft.PowerShell.EditorServices
1111
{
@@ -15,11 +15,68 @@ namespace Microsoft.PowerShell.EditorServices
1515
/// </summary>
1616
public class BreakpointDetails
1717
{
18+
/// <summary>
19+
/// Gets or sets a boolean indicator that if true, breakpoint could be set
20+
/// (but not necessarily at the desired location).
21+
/// </summary>
22+
public bool Verified { get; set; }
23+
24+
/// <summary>
25+
/// Gets or set an optional message about the state of the breakpoint. This is shown to the user
26+
/// and can be used to explain why a breakpoint could not be verified.
27+
/// </summary>
28+
public string Message { get; set; }
29+
30+
/// <summary>
31+
/// Gets the source where the breakpoint is located. Used only for debug purposes.
32+
/// </summary>
33+
public string Source { get; private set; }
34+
1835
/// <summary>
1936
/// Gets the line number at which the breakpoint is set.
2037
/// </summary>
2138
public int LineNumber { get; private set; }
2239

40+
/// <summary>
41+
/// Gets the column number at which the breakpoint is set. If null, the default of 1 is used.
42+
/// </summary>
43+
public int? ColumnNumber { get; private set; }
44+
45+
/// <summary>
46+
/// Gets the breakpoint condition string.
47+
/// </summary>
48+
public string Condition { get; private set; }
49+
50+
private BreakpointDetails()
51+
{
52+
}
53+
54+
/// <summary>
55+
/// Creates an instance of the BreakpointDetails class from the individual
56+
/// pieces of breakpoint information provided by the client.
57+
/// </summary>
58+
/// <param name="source"></param>
59+
/// <param name="line"></param>
60+
/// <param name="column"></param>
61+
/// <param name="condition"></param>
62+
/// <returns></returns>
63+
public static BreakpointDetails Create(
64+
string source,
65+
int line,
66+
int? column = null,
67+
string condition = null)
68+
{
69+
Validate.IsNotNull("source", source);
70+
71+
return new BreakpointDetails
72+
{
73+
Source = source,
74+
LineNumber = line,
75+
ColumnNumber = column,
76+
Condition = condition
77+
};
78+
}
79+
2380
/// <summary>
2481
/// Creates an instance of the BreakpointDetails class from a
2582
/// PowerShell Breakpoint object.
@@ -31,18 +88,26 @@ public static BreakpointDetails Create(Breakpoint breakpoint)
3188
Validate.IsNotNull("breakpoint", breakpoint);
3289

3390
LineBreakpoint lineBreakpoint = breakpoint as LineBreakpoint;
34-
if (lineBreakpoint != null)
35-
{
36-
return new BreakpointDetails
37-
{
38-
LineNumber = lineBreakpoint.Line
39-
};
40-
}
41-
else
91+
if (lineBreakpoint == null)
4292
{
4393
throw new ArgumentException(
4494
"Expected breakpoint type:" + breakpoint.GetType().Name);
4595
}
96+
97+
var breakpointDetails = new BreakpointDetails
98+
{
99+
Verified = true,
100+
Source = lineBreakpoint.Script,
101+
LineNumber = lineBreakpoint.Line,
102+
Condition = lineBreakpoint.Action?.ToString()
103+
};
104+
105+
if (lineBreakpoint.Column > 0)
106+
{
107+
breakpointDetails.ColumnNumber = lineBreakpoint.Column;
108+
}
109+
110+
return breakpointDetails;
46111
}
47112
}
48113
}

0 commit comments

Comments
 (0)